payload-intl 0.0.2 → 0.0.4

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.
Files changed (69) hide show
  1. package/dist/components/MessageController.js +29 -28
  2. package/dist/components/MessageController.js.map +1 -1
  3. package/dist/components/MessagesForm.js +92 -76
  4. package/dist/components/MessagesForm.js.map +1 -1
  5. package/dist/components/actions/JsonImport.d.ts +1 -1
  6. package/dist/components/actions/JsonImport.js +63 -0
  7. package/dist/components/actions/JsonImport.js.map +1 -0
  8. package/dist/components/actions/Move.d.ts +1 -1
  9. package/dist/components/inputs/InputWrapper.d.ts +1 -1
  10. package/dist/components/inputs/InputWrapper.js +24 -18
  11. package/dist/components/inputs/InputWrapper.js.map +1 -1
  12. package/dist/components/inputs/MessageInput.d.ts +1 -1
  13. package/dist/components/inputs/MessageInput.js +27 -41
  14. package/dist/components/inputs/MessageInput.js.map +1 -1
  15. package/dist/components/inputs/RichTextInput.js +62 -58
  16. package/dist/components/inputs/RichTextInput.js.map +1 -1
  17. package/dist/components/inputs/toolbar/AlignmentControls.d.ts +1 -1
  18. package/dist/components/inputs/toolbar/AlignmentControls.js +47 -44
  19. package/dist/components/inputs/toolbar/AlignmentControls.js.map +1 -1
  20. package/dist/components/inputs/toolbar/BlockElementSelect.d.ts +1 -1
  21. package/dist/components/inputs/toolbar/BlockElementSelect.js +60 -54
  22. package/dist/components/inputs/toolbar/BlockElementSelect.js.map +1 -1
  23. package/dist/components/inputs/toolbar/LinkEditor.d.ts +1 -1
  24. package/dist/components/inputs/toolbar/LinkEditor.js +182 -170
  25. package/dist/components/inputs/toolbar/LinkEditor.js.map +1 -1
  26. package/dist/components/inputs/toolbar/MarkControls.d.ts +1 -1
  27. package/dist/components/inputs/toolbar/MarkControls.js +29 -28
  28. package/dist/components/inputs/toolbar/MarkControls.js.map +1 -1
  29. package/dist/components/inputs/toolbar/RichTextToolbar.d.ts +1 -1
  30. package/dist/components/inputs/toolbar/RichTextToolbar.js +29 -26
  31. package/dist/components/inputs/toolbar/RichTextToolbar.js.map +1 -1
  32. package/dist/components/inputs/variables/VariableChip.d.ts +1 -1
  33. package/dist/components/inputs/variables/VariableChip.js +55 -49
  34. package/dist/components/inputs/variables/VariableChip.js.map +1 -1
  35. package/dist/components/inputs/variables/VariableSuggestion.d.ts +1 -1
  36. package/dist/components/inputs/variables/VariableSuggestion.js +24 -23
  37. package/dist/components/inputs/variables/VariableSuggestion.js.map +1 -1
  38. package/dist/components/inputs/variables/editors/DateVariableEditor.d.ts +1 -1
  39. package/dist/components/inputs/variables/editors/PluralVariableEditor.d.ts +1 -1
  40. package/dist/components/inputs/variables/editors/PluralVariableEditor.js +151 -122
  41. package/dist/components/inputs/variables/editors/PluralVariableEditor.js.map +1 -1
  42. package/dist/components/inputs/variables/editors/SelectVariableEditor.d.ts +1 -1
  43. package/dist/components/inputs/variables/editors/SelectVariableEditor.js +33 -29
  44. package/dist/components/inputs/variables/editors/SelectVariableEditor.js.map +1 -1
  45. package/dist/components/inputs/variables/editors/TagVariableEditor.d.ts +1 -1
  46. package/dist/components/inputs/variables/editors/TagVariableEditor.js +13 -12
  47. package/dist/components/inputs/variables/editors/TagVariableEditor.js.map +1 -1
  48. package/dist/components/inputs/variables/editors/TimeVariableEditor.d.ts +1 -1
  49. package/dist/components/inputs/variables/pickers/NumericVariablePicker.d.ts +1 -1
  50. package/dist/components/inputs/variables/pickers/NumericVariablePicker.js +40 -36
  51. package/dist/components/inputs/variables/pickers/NumericVariablePicker.js.map +1 -1
  52. package/dist/components/inputs/variables/pickers/TemporalElementEditor.d.ts +1 -1
  53. package/dist/components/layout/MessageField.js +42 -38
  54. package/dist/components/layout/MessageField.js.map +1 -1
  55. package/dist/components/layout/MessagesTabs.js +31 -30
  56. package/dist/components/layout/MessagesTabs.js.map +1 -1
  57. package/dist/components/layout/MessagesTree.js +52 -51
  58. package/dist/components/layout/MessagesTree.js.map +1 -1
  59. package/dist/context/messages-form.d.ts +1 -1
  60. package/dist/context/messages-form.js +12 -11
  61. package/dist/context/messages-form.js.map +1 -1
  62. package/dist/exports/link.d.ts +1 -1
  63. package/dist/exports/link.js +11 -10
  64. package/dist/exports/link.js.map +1 -1
  65. package/dist/exports/view.d.ts +1 -1
  66. package/dist/exports/view.js +43 -40
  67. package/dist/exports/view.js.map +1 -1
  68. package/dist/types.d.ts +2 -2
  69. package/package.json +1 -2
@@ -1,149 +1,178 @@
1
- import { TYPE as f } from "@formatjs/icu-messageformat-parser";
2
- import { IconX as b } from "@tabler/icons-react";
3
- import { Popover as n } from "radix-ui";
4
- import { useMemo as g, useImperativeHandle as E, Fragment as v } from "react";
5
- import { useForm as R, useFieldArray as h, Controller as y } from "react-hook-form";
6
- import { cn as x } from "../../../../utils/cn.js";
7
- import { serializeICUMessage as c, parseICUMessage as N } from "../../../../utils/icu-tranform.js";
8
- const w = ["zero", "one", "two", "few", "many"];
9
- function k({
10
- variableName: i,
1
+ import { jsxs as o, jsx as r, Fragment as g } from "react/jsx-runtime";
2
+ import { TYPE as b } from "@formatjs/icu-messageformat-parser";
3
+ import { IconX as v } from "@tabler/icons-react";
4
+ import { Popover as i } from "radix-ui";
5
+ import { useMemo as x, useImperativeHandle as N, Fragment as y } from "react";
6
+ import { useForm as w, useFieldArray as C, Controller as F } from "react-hook-form";
7
+ import { cn as O } from "../../../../utils/cn.js";
8
+ import { serializeICUMessage as m, parseICUMessage as j } from "../../../../utils/icu-tranform.js";
9
+ const z = ["zero", "one", "two", "few", "many"];
10
+ function A({
11
+ variableName: u,
11
12
  element: l,
12
- ref: u
13
+ ref: p
13
14
  }) {
14
- const d = g(() => {
15
+ const f = x(() => {
15
16
  const { other: e, ...t } = l?.options ?? {};
16
17
  return {
17
18
  offset: l?.offset ?? 0,
18
- options: Object.entries(t).map(([r, o]) => ({
19
- name: r,
20
- content: c(o.value)
19
+ options: Object.entries(t).map(([n, s]) => ({
20
+ name: n,
21
+ content: m(s.value)
21
22
  })),
22
- other: c(e ? e.value : [])
23
+ other: m(e ? e.value : [])
23
24
  };
24
- }, [l]), { control: m, register: s, getValues: p } = R({
25
- defaultValues: d
25
+ }, [l]), { control: c, register: d, getValues: h } = w({
26
+ defaultValues: f
26
27
  });
27
- E(u, () => ({
28
+ N(p, () => ({
28
29
  getValue: () => {
29
- const e = p(), t = {
30
- type: f.plural,
31
- value: i,
30
+ const e = h(), t = {
31
+ type: b.plural,
32
+ value: u,
32
33
  offset: e.offset,
33
34
  pluralType: l?.pluralType ?? "cardinal",
34
35
  options: Object.fromEntries(
35
- e.options.map(({ name: r, content: o }) => [
36
- r,
37
- { value: N(o) }
36
+ e.options.map(({ name: n, content: s }) => [
37
+ n,
38
+ { value: j(s) }
38
39
  ])
39
40
  )
40
41
  };
41
- return c([t]);
42
+ return m([t]);
42
43
  }
43
44
  }));
44
- const a = h({
45
- control: m,
45
+ const a = C({
46
+ control: c,
46
47
  name: "options"
47
48
  });
48
- return /* @__PURE__ */ React.createElement("div", { className: "flex flex-col gap-3" }, /* @__PURE__ */ React.createElement("fieldset", { className: "mx-0 grid grid-cols-[3rem_8rem_1.5rem] gap-y-2 rounded-md border border-border px-2 pr-0" }, /* @__PURE__ */ React.createElement("legend", null, "Options"), a.fields.map((e, t) => /* @__PURE__ */ React.createElement(v, { key: e.id }, /* @__PURE__ */ React.createElement("label", { htmlFor: `options.${t}` }, e.name), /* @__PURE__ */ React.createElement(
49
- "input",
50
- {
51
- className: "focus:outline-none",
52
- type: "text",
53
- ...s(`options.${t}.content`, { required: !0 })
54
- }
55
- ), /* @__PURE__ */ React.createElement(
56
- "button",
57
- {
58
- className: "ml-auto flex cursor-pointer items-center justify-center border-none bg-transparent p-0 hover:text-error",
59
- type: "button",
60
- onClick: () => a.remove(t)
61
- },
62
- /* @__PURE__ */ React.createElement(b, { size: 16 })
63
- ))), /* @__PURE__ */ React.createElement(React.Fragment, null, /* @__PURE__ */ React.createElement("label", { htmlFor: "other" }, "other"), /* @__PURE__ */ React.createElement(
64
- "input",
65
- {
66
- type: "text",
67
- className: "col-span-2 focus:outline-none",
68
- ...s("other", { required: !0 })
69
- }
70
- ))), /* @__PURE__ */ React.createElement("div", { className: "grid grid-cols-2 items-center gap-2" }, /* @__PURE__ */ React.createElement("label", { className: "flex items-center gap-3 pl-2" }, "offset", /* @__PURE__ */ React.createElement(
71
- "input",
72
- {
73
- className: "w-8 text-center",
74
- type: "numeric",
75
- placeholder: "0",
76
- ...s("offset")
77
- }
78
- )), /* @__PURE__ */ React.createElement(n.Root, null, /* @__PURE__ */ React.createElement(n.Trigger, null, "Add Option"), /* @__PURE__ */ React.createElement(n.Portal, null, /* @__PURE__ */ React.createElement(
79
- n.Content,
80
- {
81
- sideOffset: 4,
82
- className: "z-50 max-h-(--radix-dropdown-menu-content-available-height) min-w-[8rem] origin-(--radix-dropdown-menu-content-transform-origin) overflow-x-hidden overflow-y-auto rounded-md border border-border bg-elevation-50 shadow-md data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2 data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=closed]:zoom-out-95 data-[state=open]:animate-in data-[state=open]:fade-in-0 data-[state=open]:zoom-in-95"
83
- },
84
- /* @__PURE__ */ React.createElement("div", { className: "flex flex-col" }, w.filter(
85
- (e) => a.fields.every((t) => t.name !== e)
86
- ).map((e) => /* @__PURE__ */ React.createElement(
87
- n.Close,
88
- {
89
- key: e,
90
- className: x(
91
- "cursor-pointer border-none bg-transparent px-1 hover:bg-elevation-250"
49
+ return /* @__PURE__ */ o("div", { className: "flex flex-col gap-3", children: [
50
+ /* @__PURE__ */ o("fieldset", { className: "mx-0 grid grid-cols-[3rem_8rem_1.5rem] gap-y-2 rounded-md border border-border px-2 pr-0", children: [
51
+ /* @__PURE__ */ r("legend", { children: "Options" }),
52
+ a.fields.map((e, t) => /* @__PURE__ */ o(y, { children: [
53
+ /* @__PURE__ */ r("label", { htmlFor: `options.${t}`, children: e.name }),
54
+ /* @__PURE__ */ r(
55
+ "input",
56
+ {
57
+ className: "focus:outline-none",
58
+ type: "text",
59
+ ...d(`options.${t}.content`, { required: !0 })
60
+ }
92
61
  ),
93
- onClick: () => {
94
- a.append(
95
- {
96
- name: e,
97
- content: ""
98
- },
99
- {
100
- shouldFocus: !0
101
- }
102
- );
103
- }
104
- },
105
- e
106
- ))),
107
- /* @__PURE__ */ React.createElement("div", { className: "flex items-center justify-between gap-2 border-t border-border p-2" }, /* @__PURE__ */ React.createElement("label", { htmlFor: "customValue" }, "custom"), /* @__PURE__ */ React.createElement(
108
- y,
109
- {
110
- control: m,
111
- name: "customValue",
112
- render: ({ field: e }) => (
113
- // eslint-disable-next-line jsx-a11y/control-has-associated-label
114
- /* @__PURE__ */ React.createElement(
115
- "input",
116
- {
117
- type: "numeric",
118
- className: "w-8 rounded-sm border-transparent text-center focus:border-border focus:outline-none",
119
- placeholder: "=0",
120
- min: 0,
121
- value: e.value ?? "",
122
- onChange: ({ currentTarget: { value: t } }) => {
123
- const r = Number(t);
124
- isNaN(r) || r < 0 || e.onChange(r);
125
- },
126
- onKeyDown: (t) => {
127
- t.key !== "Enter" || e.value === void 0 || a.fields.some(
128
- (o) => o.name === `=${e.value}`
129
- ) || (a.append(
130
- {
131
- name: `=${e.value}`,
132
- content: ""
62
+ /* @__PURE__ */ r(
63
+ "button",
64
+ {
65
+ className: "ml-auto flex cursor-pointer items-center justify-center border-none bg-transparent p-0 hover:text-error",
66
+ type: "button",
67
+ onClick: () => a.remove(t),
68
+ children: /* @__PURE__ */ r(v, { size: 16 })
69
+ }
70
+ )
71
+ ] }, e.id)),
72
+ /* @__PURE__ */ o(g, { children: [
73
+ /* @__PURE__ */ r("label", { htmlFor: "other", children: "other" }),
74
+ /* @__PURE__ */ r(
75
+ "input",
76
+ {
77
+ type: "text",
78
+ className: "col-span-2 focus:outline-none",
79
+ ...d("other", { required: !0 })
80
+ }
81
+ )
82
+ ] })
83
+ ] }),
84
+ /* @__PURE__ */ o("div", { className: "grid grid-cols-2 items-center gap-2", children: [
85
+ /* @__PURE__ */ o("label", { className: "flex items-center gap-3 pl-2", children: [
86
+ "offset",
87
+ /* @__PURE__ */ r(
88
+ "input",
89
+ {
90
+ className: "w-8 text-center",
91
+ type: "numeric",
92
+ placeholder: "0",
93
+ ...d("offset")
94
+ }
95
+ )
96
+ ] }),
97
+ /* @__PURE__ */ o(i.Root, { children: [
98
+ /* @__PURE__ */ r(i.Trigger, { children: "Add Option" }),
99
+ /* @__PURE__ */ r(i.Portal, { children: /* @__PURE__ */ o(
100
+ i.Content,
101
+ {
102
+ sideOffset: 4,
103
+ className: "z-50 max-h-(--radix-dropdown-menu-content-available-height) min-w-[8rem] origin-(--radix-dropdown-menu-content-transform-origin) overflow-x-hidden overflow-y-auto rounded-md border border-border bg-elevation-50 shadow-md data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2 data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=closed]:zoom-out-95 data-[state=open]:animate-in data-[state=open]:fade-in-0 data-[state=open]:zoom-in-95",
104
+ children: [
105
+ /* @__PURE__ */ r("div", { className: "flex flex-col", children: z.filter(
106
+ (e) => a.fields.every((t) => t.name !== e)
107
+ ).map((e) => /* @__PURE__ */ r(
108
+ i.Close,
109
+ {
110
+ className: O(
111
+ "cursor-pointer border-none bg-transparent px-1 hover:bg-elevation-250"
112
+ ),
113
+ onClick: () => {
114
+ a.append(
115
+ {
116
+ name: e,
117
+ content: ""
118
+ },
119
+ {
120
+ shouldFocus: !0
121
+ }
122
+ );
133
123
  },
124
+ children: e
125
+ },
126
+ e
127
+ )) }),
128
+ /* @__PURE__ */ o("div", { className: "flex items-center justify-between gap-2 border-t border-border p-2", children: [
129
+ /* @__PURE__ */ r("label", { htmlFor: "customValue", children: "custom" }),
130
+ /* @__PURE__ */ r(
131
+ F,
134
132
  {
135
- shouldFocus: !0
133
+ control: c,
134
+ name: "customValue",
135
+ render: ({ field: e }) => (
136
+ // eslint-disable-next-line jsx-a11y/control-has-associated-label
137
+ /* @__PURE__ */ r(
138
+ "input",
139
+ {
140
+ type: "numeric",
141
+ className: "w-8 rounded-sm border-transparent text-center focus:border-border focus:outline-none",
142
+ placeholder: "=0",
143
+ min: 0,
144
+ value: e.value ?? "",
145
+ onChange: ({ currentTarget: { value: t } }) => {
146
+ const n = Number(t);
147
+ isNaN(n) || n < 0 || e.onChange(n);
148
+ },
149
+ onKeyDown: (t) => {
150
+ t.key !== "Enter" || e.value === void 0 || a.fields.some(
151
+ (s) => s.name === `=${e.value}`
152
+ ) || (a.append(
153
+ {
154
+ name: `=${e.value}`,
155
+ content: ""
156
+ },
157
+ {
158
+ shouldFocus: !0
159
+ }
160
+ ), e.onChange(void 0));
161
+ }
162
+ }
163
+ )
164
+ )
136
165
  }
137
- ), e.onChange(void 0));
138
- }
139
- }
140
- )
141
- )
142
- }
143
- ))
144
- )))));
166
+ )
167
+ ] })
168
+ ]
169
+ }
170
+ ) })
171
+ ] })
172
+ ] })
173
+ ] });
145
174
  }
146
175
  export {
147
- k as PluralVariableEditor
176
+ A as PluralVariableEditor
148
177
  };
149
178
  //# sourceMappingURL=PluralVariableEditor.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"PluralVariableEditor.js","sources":["../../../../../src/components/inputs/variables/editors/PluralVariableEditor.tsx"],"sourcesContent":["import { TYPE } from \"@formatjs/icu-messageformat-parser\";\nimport { IconX } from \"@tabler/icons-react\";\nimport { Popover } from \"radix-ui\";\nimport { Fragment, useImperativeHandle, useMemo } from \"react\";\nimport { Controller, useFieldArray, useForm } from \"react-hook-form\";\n\nimport type { PluralElement } from \"@/types\";\nimport { cn } from \"@/utils/cn\";\nimport { parseICUMessage, serializeICUMessage } from \"@/utils/icu-tranform\";\n\nconst NAMED_PLURAL_OPTIONS = [\"zero\", \"one\", \"two\", \"few\", \"many\"] as const;\n\nexport interface PluralVariableEditorProps {\n variableName: string;\n element: PluralElement | undefined;\n ref: React.Ref<{ getValue: () => string }>;\n}\n\n// TODO add support for selectordinal (\"pluralType\": \"ordinal\")\n\nexport function PluralVariableEditor({\n variableName,\n element,\n ref,\n}: PluralVariableEditorProps) {\n const config = useMemo<{\n offset: number;\n options: { name: string; content: string }[];\n other: string;\n }>(() => {\n const { other, ...options } = element?.options ?? {};\n return {\n offset: element?.offset ?? 0,\n options: Object.entries(options).map(([name, option]) => ({\n name,\n content: serializeICUMessage(option.value),\n })),\n other: serializeICUMessage(other ? other.value : []),\n };\n }, [element]);\n\n const { control, register, getValues } = useForm<{\n offset: number;\n options: { name: string; content: string }[];\n other: string;\n customValue?: number;\n }>({\n defaultValues: config,\n });\n\n useImperativeHandle(ref, () => ({\n getValue: () => {\n const values = getValues();\n const updatedElement: PluralElement = {\n type: TYPE.plural,\n value: variableName,\n offset: values.offset,\n pluralType: element?.pluralType ?? \"cardinal\",\n options: Object.fromEntries(\n values.options.map(({ name, content }) => [\n name,\n { value: parseICUMessage(content) },\n ]),\n ),\n };\n return serializeICUMessage([updatedElement]);\n },\n }));\n\n const options = useFieldArray({\n control,\n name: \"options\",\n });\n\n return (\n <div className=\"flex flex-col gap-3\">\n <fieldset className=\"mx-0 grid grid-cols-[3rem_8rem_1.5rem] gap-y-2 rounded-md border border-border px-2 pr-0\">\n <legend>Options</legend>\n {options.fields.map((field, index) => (\n <Fragment key={field.id}>\n <label htmlFor={`options.${index}`}>{field.name}</label>\n {/* // TODO add support for variable mentions */}\n <input\n className=\"focus:outline-none\"\n type=\"text\"\n {...register(`options.${index}.content`, { required: true })}\n />\n <button\n className=\"ml-auto flex cursor-pointer items-center justify-center border-none bg-transparent p-0 hover:text-error\"\n type=\"button\"\n onClick={() => options.remove(index)}\n >\n <IconX size={16} />\n </button>\n </Fragment>\n ))}\n\n <>\n <label htmlFor=\"other\">other</label>\n {/* // TODO add support for variable mentions */}\n <input\n type=\"text\"\n className=\"col-span-2 focus:outline-none\"\n {...register(\"other\", { required: true })}\n />\n </>\n </fieldset>\n <div className=\"grid grid-cols-2 items-center gap-2\">\n <label className=\"flex items-center gap-3 pl-2\">\n offset\n <input\n className=\"w-8 text-center\"\n type=\"numeric\"\n placeholder=\"0\"\n {...register(\"offset\")}\n />\n </label>\n <Popover.Root>\n <Popover.Trigger>Add Option</Popover.Trigger>\n <Popover.Portal>\n <Popover.Content\n sideOffset={4}\n className=\"z-50 max-h-(--radix-dropdown-menu-content-available-height) min-w-[8rem] origin-(--radix-dropdown-menu-content-transform-origin) overflow-x-hidden overflow-y-auto rounded-md border border-border bg-elevation-50 shadow-md data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2 data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=closed]:zoom-out-95 data-[state=open]:animate-in data-[state=open]:fade-in-0 data-[state=open]:zoom-in-95\"\n >\n <div className=\"flex flex-col\">\n {NAMED_PLURAL_OPTIONS.filter((option) =>\n options.fields.every((field) => field.name !== option),\n ).map((option) => (\n <Popover.Close\n key={option}\n className={cn(\n \"cursor-pointer border-none bg-transparent px-1 hover:bg-elevation-250\",\n )}\n onClick={() => {\n // TODO ensure the fields are always in the same order as staticPluralOptions\n options.append(\n {\n name: option,\n content: \"\",\n },\n {\n shouldFocus: true,\n },\n );\n }}\n >\n {option}\n </Popover.Close>\n ))}\n </div>\n\n <div className=\"flex items-center justify-between gap-2 border-t border-border p-2\">\n <label htmlFor=\"customValue\">custom</label>\n <Controller\n control={control}\n name=\"customValue\"\n render={({ field }) => (\n // eslint-disable-next-line jsx-a11y/control-has-associated-label\n <input\n type=\"numeric\"\n className=\"w-8 rounded-sm border-transparent text-center focus:border-border focus:outline-none\"\n placeholder=\"=0\"\n min={0}\n value={field.value ?? \"\"}\n onChange={({ currentTarget: { value } }) => {\n const number = Number(value);\n if (isNaN(number)) return;\n if (number < 0) return;\n field.onChange(number);\n }}\n onKeyDown={(e) => {\n if (e.key !== \"Enter\") return;\n if (field.value === undefined) return;\n const isUnique = !options.fields.some(\n (existingField) =>\n existingField.name === `=${field.value}`,\n );\n if (!isUnique) return; // TODO maybe show error?\n options.append(\n {\n name: `=${field.value}`,\n content: \"\",\n },\n {\n shouldFocus: true,\n },\n );\n field.onChange(undefined);\n }}\n />\n )}\n />\n </div>\n </Popover.Content>\n </Popover.Portal>\n </Popover.Root>\n </div>\n </div>\n );\n}\n"],"names":["NAMED_PLURAL_OPTIONS","PluralVariableEditor","variableName","element","ref","config","useMemo","other","options","name","option","serializeICUMessage","control","register","getValues","useForm","useImperativeHandle","values","updatedElement","TYPE","content","parseICUMessage","useFieldArray","field","index","Fragment","IconX","Popover","cn","Controller","value","number","e","existingField"],"mappings":";;;;;;;AAUA,MAAMA,IAAuB,CAAC,QAAQ,OAAO,OAAO,OAAO,MAAM;AAU1D,SAASC,EAAqB;AAAA,EACnC,cAAAC;AAAA,EACA,SAAAC;AAAA,EACA,KAAAC;AACF,GAA8B;AAC5B,QAAMC,IAASC,EAIZ,MAAM;AACP,UAAM,EAAE,OAAAC,GAAO,GAAGC,MAAYL,GAAS,WAAW,CAAA;AAClD,WAAO;AAAA,MACL,QAAQA,GAAS,UAAU;AAAA,MAC3B,SAAS,OAAO,QAAQK,CAAO,EAAE,IAAI,CAAC,CAACC,GAAMC,CAAM,OAAO;AAAA,QACxD,MAAAD;AAAA,QACA,SAASE,EAAoBD,EAAO,KAAK;AAAA,MAAA,EACzC;AAAA,MACF,OAAOC,EAAoBJ,IAAQA,EAAM,QAAQ,CAAA,CAAE;AAAA,IAAA;AAAA,EAEvD,GAAG,CAACJ,CAAO,CAAC,GAEN,EAAE,SAAAS,GAAS,UAAAC,GAAU,WAAAC,EAAA,IAAcC,EAKtC;AAAA,IACD,eAAeV;AAAA,EAAA,CAChB;AAED,EAAAW,EAAoBZ,GAAK,OAAO;AAAA,IAC9B,UAAU,MAAM;AACd,YAAMa,IAASH,EAAA,GACTI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,EAAE,OAAAW,EAAA;AAAA;AAAA,UAET,sBAAA;AAAA,YAAC;AAAA,YAAA;AAAA,cACC,MAAK;AAAA,cACL,WAAU;AAAA,cACV,aAAY;AAAA,cACZ,KAAK;AAAA,cACL,OAAOA,EAAM,SAAS;AAAA,cACtB,UAAU,CAAC,EAAE,eAAe,EAAE,OAAAO,EAAA,QAAc;AAC1C,sBAAMC,IAAS,OAAOD,CAAK;AAC3B,gBAAI,MAAMC,CAAM,KACZA,IAAS,KACbR,EAAM,SAASQ,CAAM;AAAA,cACvB;AAAA,cACA,WAAW,CAACC,MAAM;AAOhB,gBANIA,EAAE,QAAQ,WACVT,EAAM,UAAU,UACFf,EAAQ,OAAO;AAAA,kBAC/B,CAACyB,MACCA,EAAc,SAAS,IAAIV,EAAM,KAAK;AAAA,gBAAA,MAG1Cf,EAAQ;AAAA,kBACN;AAAA,oBACE,MAAM,IAAIe,EAAM,KAAK;AAAA,oBACrB,SAAS;AAAA,kBAAA;AAAA,kBAEX;AAAA,oBACE,aAAa;AAAA,kBAAA;AAAA,gBACf,GAEFA,EAAM,SAAS,MAAS;AAAA,cAC1B;AAAA,YAAA;AAAA,UAAA;AAAA;AAAA,MACF;AAAA,IAAA,CAGN;AAAA,EAAA,CAEJ,CACF,CACF,CACF;AAEJ;"}
1
+ {"version":3,"file":"PluralVariableEditor.js","sources":["../../../../../src/components/inputs/variables/editors/PluralVariableEditor.tsx"],"sourcesContent":["import { TYPE } from \"@formatjs/icu-messageformat-parser\";\nimport { IconX } from \"@tabler/icons-react\";\nimport { Popover } from \"radix-ui\";\nimport { Fragment, useImperativeHandle, useMemo } from \"react\";\nimport { Controller, useFieldArray, useForm } from \"react-hook-form\";\n\nimport type { PluralElement } from \"@/types\";\nimport { cn } from \"@/utils/cn\";\nimport { parseICUMessage, serializeICUMessage } from \"@/utils/icu-tranform\";\n\nconst NAMED_PLURAL_OPTIONS = [\"zero\", \"one\", \"two\", \"few\", \"many\"] as const;\n\nexport interface PluralVariableEditorProps {\n variableName: string;\n element: PluralElement | undefined;\n ref: React.Ref<{ getValue: () => string }>;\n}\n\n// TODO add support for selectordinal (\"pluralType\": \"ordinal\")\n\nexport function PluralVariableEditor({\n variableName,\n element,\n ref,\n}: PluralVariableEditorProps) {\n const config = useMemo<{\n offset: number;\n options: { name: string; content: string }[];\n other: string;\n }>(() => {\n const { other, ...options } = element?.options ?? {};\n return {\n offset: element?.offset ?? 0,\n options: Object.entries(options).map(([name, option]) => ({\n name,\n content: serializeICUMessage(option.value),\n })),\n other: serializeICUMessage(other ? other.value : []),\n };\n }, [element]);\n\n const { control, register, getValues } = useForm<{\n offset: number;\n options: { name: string; content: string }[];\n other: string;\n customValue?: number;\n }>({\n defaultValues: config,\n });\n\n useImperativeHandle(ref, () => ({\n getValue: () => {\n const values = getValues();\n const updatedElement: PluralElement = {\n type: TYPE.plural,\n value: variableName,\n offset: values.offset,\n pluralType: element?.pluralType ?? \"cardinal\",\n options: Object.fromEntries(\n values.options.map(({ name, content }) => [\n name,\n { value: parseICUMessage(content) },\n ]),\n ),\n };\n return serializeICUMessage([updatedElement]);\n },\n }));\n\n const options = useFieldArray({\n control,\n name: \"options\",\n });\n\n return (\n <div className=\"flex flex-col gap-3\">\n <fieldset className=\"mx-0 grid grid-cols-[3rem_8rem_1.5rem] gap-y-2 rounded-md border border-border px-2 pr-0\">\n <legend>Options</legend>\n {options.fields.map((field, index) => (\n <Fragment key={field.id}>\n <label htmlFor={`options.${index}`}>{field.name}</label>\n {/* // TODO add support for variable mentions */}\n <input\n className=\"focus:outline-none\"\n type=\"text\"\n {...register(`options.${index}.content`, { required: true })}\n />\n <button\n className=\"ml-auto flex cursor-pointer items-center justify-center border-none bg-transparent p-0 hover:text-error\"\n type=\"button\"\n onClick={() => options.remove(index)}\n >\n <IconX size={16} />\n </button>\n </Fragment>\n ))}\n\n <>\n <label htmlFor=\"other\">other</label>\n {/* // TODO add support for variable mentions */}\n <input\n type=\"text\"\n className=\"col-span-2 focus:outline-none\"\n {...register(\"other\", { required: true })}\n />\n </>\n </fieldset>\n <div className=\"grid grid-cols-2 items-center gap-2\">\n <label className=\"flex items-center gap-3 pl-2\">\n offset\n <input\n className=\"w-8 text-center\"\n type=\"numeric\"\n placeholder=\"0\"\n {...register(\"offset\")}\n />\n </label>\n <Popover.Root>\n <Popover.Trigger>Add Option</Popover.Trigger>\n <Popover.Portal>\n <Popover.Content\n sideOffset={4}\n className=\"z-50 max-h-(--radix-dropdown-menu-content-available-height) min-w-[8rem] origin-(--radix-dropdown-menu-content-transform-origin) overflow-x-hidden overflow-y-auto rounded-md border border-border bg-elevation-50 shadow-md data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2 data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=closed]:zoom-out-95 data-[state=open]:animate-in data-[state=open]:fade-in-0 data-[state=open]:zoom-in-95\"\n >\n <div className=\"flex flex-col\">\n {NAMED_PLURAL_OPTIONS.filter((option) =>\n options.fields.every((field) => field.name !== option),\n ).map((option) => (\n <Popover.Close\n key={option}\n className={cn(\n \"cursor-pointer border-none bg-transparent px-1 hover:bg-elevation-250\",\n )}\n onClick={() => {\n // TODO ensure the fields are always in the same order as staticPluralOptions\n options.append(\n {\n name: option,\n content: \"\",\n },\n {\n shouldFocus: true,\n },\n );\n }}\n >\n {option}\n </Popover.Close>\n ))}\n </div>\n\n <div className=\"flex items-center justify-between gap-2 border-t border-border p-2\">\n <label htmlFor=\"customValue\">custom</label>\n <Controller\n control={control}\n name=\"customValue\"\n render={({ field }) => (\n // eslint-disable-next-line jsx-a11y/control-has-associated-label\n <input\n type=\"numeric\"\n className=\"w-8 rounded-sm border-transparent text-center focus:border-border focus:outline-none\"\n placeholder=\"=0\"\n min={0}\n value={field.value ?? \"\"}\n onChange={({ currentTarget: { value } }) => {\n const number = Number(value);\n if (isNaN(number)) return;\n if (number < 0) return;\n field.onChange(number);\n }}\n onKeyDown={(e) => {\n if (e.key !== \"Enter\") return;\n if (field.value === undefined) return;\n const isUnique = !options.fields.some(\n (existingField) =>\n existingField.name === `=${field.value}`,\n );\n if (!isUnique) return; // TODO maybe show error?\n options.append(\n {\n name: `=${field.value}`,\n content: \"\",\n },\n {\n shouldFocus: true,\n },\n );\n field.onChange(undefined);\n }}\n />\n )}\n />\n </div>\n </Popover.Content>\n </Popover.Portal>\n </Popover.Root>\n </div>\n </div>\n );\n}\n"],"names":["NAMED_PLURAL_OPTIONS","PluralVariableEditor","variableName","element","ref","config","useMemo","other","options","name","option","serializeICUMessage","control","register","getValues","useForm","useImperativeHandle","values","updatedElement","TYPE","content","parseICUMessage","useFieldArray","jsxs","jsx","field","index","Fragment","IconX","Popover","cn","Controller","value","number","e","existingField"],"mappings":";;;;;;;;AAUA,MAAMA,IAAuB,CAAC,QAAQ,OAAO,OAAO,OAAO,MAAM;AAU1D,SAASC,EAAqB;AAAA,EACnC,cAAAC;AAAA,EACA,SAAAC;AAAA,EACA,KAAAC;AACF,GAA8B;AAC5B,QAAMC,IAASC,EAIZ,MAAM;AACP,UAAM,EAAE,OAAAC,GAAO,GAAGC,MAAYL,GAAS,WAAW,CAAA;AAClD,WAAO;AAAA,MACL,QAAQA,GAAS,UAAU;AAAA,MAC3B,SAAS,OAAO,QAAQK,CAAO,EAAE,IAAI,CAAC,CAACC,GAAMC,CAAM,OAAO;AAAA,QACxD,MAAAD;AAAA,QACA,SAASE,EAAoBD,EAAO,KAAK;AAAA,MAAA,EACzC;AAAA,MACF,OAAOC,EAAoBJ,IAAQA,EAAM,QAAQ,CAAA,CAAE;AAAA,IAAA;AAAA,EAEvD,GAAG,CAACJ,CAAO,CAAC,GAEN,EAAE,SAAAS,GAAS,UAAAC,GAAU,WAAAC,EAAA,IAAcC,EAKtC;AAAA,IACD,eAAeV;AAAA,EAAA,CAChB;AAED,EAAAW,EAAoBZ,GAAK,OAAO;AAAA,IAC9B,UAAU,MAAM;AACd,YAAMa,IAASH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;AAAA,EAAA,GACF;AAEJ;"}
@@ -3,4 +3,4 @@ export interface SelectVariableEditorProps {
3
3
  element: SelectElement;
4
4
  onUpdate: (value: string) => void;
5
5
  }
6
- export declare function SelectVariableEditor({ element, onUpdate, }: SelectVariableEditorProps): import("react").JSX.Element;
6
+ export declare function SelectVariableEditor({ element, onUpdate, }: SelectVariableEditorProps): import("react/jsx-runtime").JSX.Element;
@@ -1,42 +1,46 @@
1
- import { useMemo as u, useEffect as f } from "react";
2
- import { useForm as d, useFieldArray as E } from "react-hook-form";
3
- import { serializeICUMessage as o, parseICUMessage as g } from "../../../../utils/icu-tranform.js";
4
- function N({
5
- element: a,
6
- onUpdate: s
1
+ import { jsx as t, jsxs as f } from "react/jsx-runtime";
2
+ import { useMemo as d, useEffect as x } from "react";
3
+ import { useForm as g, useFieldArray as v } from "react-hook-form";
4
+ import { serializeICUMessage as n, parseICUMessage as b } from "../../../../utils/icu-tranform.js";
5
+ function M({
6
+ element: s,
7
+ onUpdate: a
7
8
  }) {
8
- const n = u(
9
- () => Object.entries(a.options).map(([e, t]) => ({
9
+ const r = d(
10
+ () => Object.entries(s.options).map(([e, o]) => ({
10
11
  name: e,
11
- content: o(t.value)
12
+ content: n(o.value)
12
13
  })),
13
- [a]
14
- ), { control: c, register: r, getValues: l } = d({
15
- defaultValues: { options: n }
16
- }), { fields: m } = E({
17
- control: c,
14
+ [s]
15
+ ), { control: i, register: l, getValues: c } = g({
16
+ defaultValues: { options: r }
17
+ }), { fields: m } = v({
18
+ control: i,
18
19
  name: "options"
19
20
  });
20
- return f(() => () => {
21
- const e = l(), t = {
22
- ...a,
21
+ return x(() => () => {
22
+ const e = c(), o = {
23
+ ...s,
23
24
  options: Object.fromEntries(
24
- e.options.map(({ name: i, content: p }) => [
25
- i,
26
- { value: g(p) }
25
+ e.options.map(({ name: p, content: u }) => [
26
+ p,
27
+ { value: b(u) }
27
28
  ])
28
29
  )
29
30
  };
30
- s(o([t]));
31
- }, []), /* @__PURE__ */ React.createElement("div", { className: "flex flex-col gap-2 p-3" }, m.map((e, t) => /* @__PURE__ */ React.createElement("div", { key: e.name, className: "flex flex-col gap-1" }, /* @__PURE__ */ React.createElement("label", { className: "text-sm font-medium" }, e.name), /* @__PURE__ */ React.createElement(
32
- "input",
33
- {
34
- className: "focus:outline-none",
35
- ...r(`options.${t}.content`)
36
- }
37
- ))));
31
+ a(n([o]));
32
+ }, []), /* @__PURE__ */ t("div", { className: "flex flex-col gap-2 p-3", children: m.map((e, o) => /* @__PURE__ */ f("div", { className: "flex flex-col gap-1", children: [
33
+ /* @__PURE__ */ t("label", { className: "text-sm font-medium", children: e.name }),
34
+ /* @__PURE__ */ t(
35
+ "input",
36
+ {
37
+ className: "focus:outline-none",
38
+ ...l(`options.${o}.content`)
39
+ }
40
+ )
41
+ ] }, e.name)) });
38
42
  }
39
43
  export {
40
- N as SelectVariableEditor
44
+ M as SelectVariableEditor
41
45
  };
42
46
  //# sourceMappingURL=SelectVariableEditor.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"SelectVariableEditor.js","sources":["../../../../../src/components/inputs/variables/editors/SelectVariableEditor.tsx"],"sourcesContent":["import { useEffect, useMemo } from \"react\";\nimport { useFieldArray, useForm } from \"react-hook-form\";\n\nimport type { SelectElement } from \"@/types\";\nimport { parseICUMessage, serializeICUMessage } from \"@/utils/icu-tranform\";\n\nexport interface SelectVariableEditorProps {\n element: SelectElement;\n onUpdate: (value: string) => void;\n}\n\nexport function SelectVariableEditor({\n element,\n onUpdate,\n}: SelectVariableEditorProps) {\n const options = useMemo<{ name: string; content: string }[]>(\n () =>\n Object.entries(element.options).map(([name, option]) => ({\n name,\n content: serializeICUMessage(option.value),\n })),\n [element],\n );\n\n const { control, register, getValues } = useForm<{\n options: { name: string; content: string }[];\n }>({\n defaultValues: { options },\n });\n const { fields } = useFieldArray({\n control,\n name: \"options\",\n });\n\n useEffect(() => {\n return () => {\n const values = getValues();\n const updatedElement: SelectElement = {\n ...element,\n options: Object.fromEntries(\n values.options.map(({ name, content }) => [\n name,\n { value: parseICUMessage(content) },\n ]),\n ),\n };\n onUpdate(serializeICUMessage([updatedElement]));\n };\n }, []);\n\n return (\n <div className=\"flex flex-col gap-2 p-3\">\n {fields.map((field, index) => (\n <div key={field.name} className=\"flex flex-col gap-1\">\n <label className=\"text-sm font-medium\">{field.name}</label>\n {/* // TODO add support for variable mentions */}\n <input\n className=\"focus:outline-none\"\n {...register(`options.${index}.content`)}\n />\n </div>\n ))}\n </div>\n );\n}\n"],"names":["SelectVariableEditor","element","onUpdate","options","useMemo","name","option","serializeICUMessage","control","register","getValues","useForm","fields","useFieldArray","useEffect","values","updatedElement","content","parseICUMessage","field","index"],"mappings":";;;AAWO,SAASA,EAAqB;AAAA,EACnC,SAAAC;AAAA,EACA,UAAAC;AACF,GAA8B;AAC5B,QAAMC,IAAUC;AAAA,IACd,MACE,OAAO,QAAQH,EAAQ,OAAO,EAAE,IAAI,CAAC,CAACI,GAAMC,CAAM,OAAO;AAAA,MACvD,MAAAD;AAAA,MACA,SAASE,EAAoBD,EAAO,KAAK;AAAA,IAAA,EACzC;AAAA,IACJ,CAACL,CAAO;AAAA,EAAA,GAGJ,EAAE,SAAAO,GAAS,UAAAC,GAAU,WAAAC,EAAA,IAAcC,EAEtC;AAAA,IACD,eAAe,EAAE,SAAAR,EAAA;AAAA,EAAQ,CAC1B,GACK,EAAE,QAAAS,EAAA,IAAWC,EAAc;AAAA,IAC/B,SAAAL;AAAA,IACA,MAAM;AAAA,EAAA,CACP;AAED,SAAAM,EAAU,MACD,MAAM;AACX,UAAMC,IAASL,EAAA,GACTM,IAAgC;AAAA,MACpC,GAAGf;AAAA,MACH,SAAS,OAAO;AAAA,QACdc,EAAO,QAAQ,IAAI,CAAC,EAAE,MAAAV,GAAM,SAAAY,QAAc;AAAA,UACxCZ;AAAA,UACA,EAAE,OAAOa,EAAgBD,CAAO,EAAA;AAAA,QAAE,CACnC;AAAA,MAAA;AAAA,IACH;AAEF,IAAAf,EAASK,EAAoB,CAACS,CAAc,CAAC,CAAC;AAAA,EAChD,GACC,CAAA,CAAE,GAGH,sBAAA,cAAC,SAAI,WAAU,0BAAA,GACZJ,EAAO,IAAI,CAACO,GAAOC,MAClB,sBAAA,cAAC,OAAA,EAAI,KAAKD,EAAM,MAAM,WAAU,sBAAA,GAC9B,sBAAA,cAAC,WAAM,WAAU,sBAAA,GAAuBA,EAAM,IAAK,GAEnD,sBAAA;AAAA,IAAC;AAAA,IAAA;AAAA,MACC,WAAU;AAAA,MACT,GAAGV,EAAS,WAAWW,CAAK,UAAU;AAAA,IAAA;AAAA,EAAA,CAE3C,CACD,CACH;AAEJ;"}
1
+ {"version":3,"file":"SelectVariableEditor.js","sources":["../../../../../src/components/inputs/variables/editors/SelectVariableEditor.tsx"],"sourcesContent":["import { useEffect, useMemo } from \"react\";\nimport { useFieldArray, useForm } from \"react-hook-form\";\n\nimport type { SelectElement } from \"@/types\";\nimport { parseICUMessage, serializeICUMessage } from \"@/utils/icu-tranform\";\n\nexport interface SelectVariableEditorProps {\n element: SelectElement;\n onUpdate: (value: string) => void;\n}\n\nexport function SelectVariableEditor({\n element,\n onUpdate,\n}: SelectVariableEditorProps) {\n const options = useMemo<{ name: string; content: string }[]>(\n () =>\n Object.entries(element.options).map(([name, option]) => ({\n name,\n content: serializeICUMessage(option.value),\n })),\n [element],\n );\n\n const { control, register, getValues } = useForm<{\n options: { name: string; content: string }[];\n }>({\n defaultValues: { options },\n });\n const { fields } = useFieldArray({\n control,\n name: \"options\",\n });\n\n useEffect(() => {\n return () => {\n const values = getValues();\n const updatedElement: SelectElement = {\n ...element,\n options: Object.fromEntries(\n values.options.map(({ name, content }) => [\n name,\n { value: parseICUMessage(content) },\n ]),\n ),\n };\n onUpdate(serializeICUMessage([updatedElement]));\n };\n }, []);\n\n return (\n <div className=\"flex flex-col gap-2 p-3\">\n {fields.map((field, index) => (\n <div key={field.name} className=\"flex flex-col gap-1\">\n <label className=\"text-sm font-medium\">{field.name}</label>\n {/* // TODO add support for variable mentions */}\n <input\n className=\"focus:outline-none\"\n {...register(`options.${index}.content`)}\n />\n </div>\n ))}\n </div>\n );\n}\n"],"names":["SelectVariableEditor","element","onUpdate","options","useMemo","name","option","serializeICUMessage","control","register","getValues","useForm","fields","useFieldArray","useEffect","values","updatedElement","content","parseICUMessage","jsx","field","index","jsxs"],"mappings":";;;;AAWO,SAASA,EAAqB;AAAA,EACnC,SAAAC;AAAA,EACA,UAAAC;AACF,GAA8B;AAC5B,QAAMC,IAAUC;AAAA,IACd,MACE,OAAO,QAAQH,EAAQ,OAAO,EAAE,IAAI,CAAC,CAACI,GAAMC,CAAM,OAAO;AAAA,MACvD,MAAAD;AAAA,MACA,SAASE,EAAoBD,EAAO,KAAK;AAAA,IAAA,EACzC;AAAA,IACJ,CAACL,CAAO;AAAA,EAAA,GAGJ,EAAE,SAAAO,GAAS,UAAAC,GAAU,WAAAC,EAAA,IAAcC,EAEtC;AAAA,IACD,eAAe,EAAE,SAAAR,EAAA;AAAA,EAAQ,CAC1B,GACK,EAAE,QAAAS,EAAA,IAAWC,EAAc;AAAA,IAC/B,SAAAL;AAAA,IACA,MAAM;AAAA,EAAA,CACP;AAED,SAAAM,EAAU,MACD,MAAM;AACX,UAAMC,IAASL,EAAA,GACTM,IAAgC;AAAA,MACpC,GAAGf;AAAA,MACH,SAAS,OAAO;AAAA,QACdc,EAAO,QAAQ,IAAI,CAAC,EAAE,MAAAV,GAAM,SAAAY,QAAc;AAAA,UACxCZ;AAAA,UACA,EAAE,OAAOa,EAAgBD,CAAO,EAAA;AAAA,QAAE,CACnC;AAAA,MAAA;AAAA,IACH;AAEF,IAAAf,EAASK,EAAoB,CAACS,CAAc,CAAC,CAAC;AAAA,EAChD,GACC,CAAA,CAAE,GAGH,gBAAAG,EAAC,OAAA,EAAI,WAAU,2BACZ,UAAAP,EAAO,IAAI,CAACQ,GAAOC,MAClB,gBAAAC,EAAC,OAAA,EAAqB,WAAU,uBAC9B,UAAA;AAAA,IAAA,gBAAAH,EAAC,SAAA,EAAM,WAAU,uBAAuB,UAAAC,EAAM,MAAK;AAAA,IAEnD,gBAAAD;AAAA,MAAC;AAAA,MAAA;AAAA,QACC,WAAU;AAAA,QACT,GAAGV,EAAS,WAAWY,CAAK,UAAU;AAAA,MAAA;AAAA,IAAA;AAAA,EACzC,EAAA,GANQD,EAAM,IAOhB,CACD,GACH;AAEJ;"}
@@ -3,4 +3,4 @@ export interface TagVariableEditorProps {
3
3
  element: TagElement;
4
4
  onUpdate: (value: string) => void;
5
5
  }
6
- export declare function TagVariableEditor({ element, onUpdate, }: TagVariableEditorProps): import("react").JSX.Element;
6
+ export declare function TagVariableEditor({ element, onUpdate, }: TagVariableEditorProps): import("react/jsx-runtime").JSX.Element;
@@ -1,32 +1,33 @@
1
- import { useMemo as i, useEffect as u } from "react";
2
- import { useForm as l } from "react-hook-form";
3
- import { serializeICUMessage as t, parseICUMessage as m } from "../../../../utils/icu-tranform.js";
4
- function g({
1
+ import { jsx as i } from "react/jsx-runtime";
2
+ import { useMemo as u, useEffect as m } from "react";
3
+ import { useForm as f } from "react-hook-form";
4
+ import { serializeICUMessage as t, parseICUMessage as l } from "../../../../utils/icu-tranform.js";
5
+ function E({
5
6
  element: e,
6
7
  onUpdate: o
7
8
  }) {
8
- const r = i(
9
+ const r = u(
9
10
  () => t(e.children),
10
11
  [e]
11
- ), { register: n, getValues: s } = l({
12
+ ), { register: s, getValues: n } = f({
12
13
  defaultValues: { content: r }
13
14
  });
14
- return u(() => () => {
15
- const { content: a } = s(), c = {
15
+ return m(() => () => {
16
+ const { content: a } = n(), c = {
16
17
  ...e,
17
- children: m(a)
18
+ children: l(a)
18
19
  };
19
20
  o(t([c]));
20
- }, []), /* @__PURE__ */ React.createElement(
21
+ }, []), /* @__PURE__ */ i(
21
22
  "textarea",
22
23
  {
23
24
  className: "p-3 focus:outline-none",
24
- ...n("content"),
25
+ ...s("content"),
25
26
  rows: 1
26
27
  }
27
28
  );
28
29
  }
29
30
  export {
30
- g as TagVariableEditor
31
+ E as TagVariableEditor
31
32
  };
32
33
  //# sourceMappingURL=TagVariableEditor.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"TagVariableEditor.js","sources":["../../../../../src/components/inputs/variables/editors/TagVariableEditor.tsx"],"sourcesContent":["import { useEffect, useMemo } from \"react\";\nimport { useForm } from \"react-hook-form\";\n\nimport type { TagElement } from \"@/types\";\nimport { parseICUMessage, serializeICUMessage } from \"@/utils/icu-tranform\";\n\nexport interface TagVariableEditorProps {\n element: TagElement;\n onUpdate: (value: string) => void;\n}\n\nexport function TagVariableEditor({\n element,\n onUpdate,\n}: TagVariableEditorProps) {\n const content = useMemo<string>(\n () => serializeICUMessage(element.children),\n [element],\n );\n\n const { register, getValues } = useForm<{ content: string }>({\n defaultValues: { content },\n });\n\n useEffect(() => {\n return () => {\n const { content } = getValues();\n // TODO find better solution for this\n const updatedElement: TagElement = {\n ...element,\n children: parseICUMessage(content),\n };\n onUpdate(serializeICUMessage([updatedElement]));\n };\n }, []);\n\n // TODO add support for variable mentions\n return (\n <textarea\n className=\"p-3 focus:outline-none\"\n {...register(\"content\")}\n rows={1}\n />\n );\n}\n"],"names":["TagVariableEditor","element","onUpdate","content","useMemo","serializeICUMessage","register","getValues","useForm","useEffect","updatedElement","parseICUMessage"],"mappings":";;;AAWO,SAASA,EAAkB;AAAA,EAChC,SAAAC;AAAA,EACA,UAAAC;AACF,GAA2B;AACzB,QAAMC,IAAUC;AAAA,IACd,MAAMC,EAAoBJ,EAAQ,QAAQ;AAAA,IAC1C,CAACA,CAAO;AAAA,EAAA,GAGJ,EAAE,UAAAK,GAAU,WAAAC,EAAA,IAAcC,EAA6B;AAAA,IAC3D,eAAe,EAAE,SAAAL,EAAA;AAAA,EAAQ,CAC1B;AAED,SAAAM,EAAU,MACD,MAAM;AACX,UAAM,EAAE,SAAAN,EAAAA,IAAYI,EAAA,GAEdG,IAA6B;AAAA,MACjC,GAAGT;AAAA,MACH,UAAUU,EAAgBR,CAAO;AAAA,IAAA;AAEnC,IAAAD,EAASG,EAAoB,CAACK,CAAc,CAAC,CAAC;AAAA,EAChD,GACC,CAAA,CAAE,GAIH,sBAAA;AAAA,IAAC;AAAA,IAAA;AAAA,MACC,WAAU;AAAA,MACT,GAAGJ,EAAS,SAAS;AAAA,MACtB,MAAM;AAAA,IAAA;AAAA,EAAA;AAGZ;"}
1
+ {"version":3,"file":"TagVariableEditor.js","sources":["../../../../../src/components/inputs/variables/editors/TagVariableEditor.tsx"],"sourcesContent":["import { useEffect, useMemo } from \"react\";\nimport { useForm } from \"react-hook-form\";\n\nimport type { TagElement } from \"@/types\";\nimport { parseICUMessage, serializeICUMessage } from \"@/utils/icu-tranform\";\n\nexport interface TagVariableEditorProps {\n element: TagElement;\n onUpdate: (value: string) => void;\n}\n\nexport function TagVariableEditor({\n element,\n onUpdate,\n}: TagVariableEditorProps) {\n const content = useMemo<string>(\n () => serializeICUMessage(element.children),\n [element],\n );\n\n const { register, getValues } = useForm<{ content: string }>({\n defaultValues: { content },\n });\n\n useEffect(() => {\n return () => {\n const { content } = getValues();\n // TODO find better solution for this\n const updatedElement: TagElement = {\n ...element,\n children: parseICUMessage(content),\n };\n onUpdate(serializeICUMessage([updatedElement]));\n };\n }, []);\n\n // TODO add support for variable mentions\n return (\n <textarea\n className=\"p-3 focus:outline-none\"\n {...register(\"content\")}\n rows={1}\n />\n );\n}\n"],"names":["TagVariableEditor","element","onUpdate","content","useMemo","serializeICUMessage","register","getValues","useForm","useEffect","updatedElement","parseICUMessage","jsx"],"mappings":";;;;AAWO,SAASA,EAAkB;AAAA,EAChC,SAAAC;AAAA,EACA,UAAAC;AACF,GAA2B;AACzB,QAAMC,IAAUC;AAAA,IACd,MAAMC,EAAoBJ,EAAQ,QAAQ;AAAA,IAC1C,CAACA,CAAO;AAAA,EAAA,GAGJ,EAAE,UAAAK,GAAU,WAAAC,EAAA,IAAcC,EAA6B;AAAA,IAC3D,eAAe,EAAE,SAAAL,EAAA;AAAA,EAAQ,CAC1B;AAED,SAAAM,EAAU,MACD,MAAM;AACX,UAAM,EAAE,SAAAN,EAAAA,IAAYI,EAAA,GAEdG,IAA6B;AAAA,MACjC,GAAGT;AAAA,MACH,UAAUU,EAAgBR,CAAO;AAAA,IAAA;AAEnC,IAAAD,EAASG,EAAoB,CAACK,CAAc,CAAC,CAAC;AAAA,EAChD,GACC,CAAA,CAAE,GAIH,gBAAAE;AAAA,IAAC;AAAA,IAAA;AAAA,MACC,WAAU;AAAA,MACT,GAAGN,EAAS,SAAS;AAAA,MACtB,MAAM;AAAA,IAAA;AAAA,EAAA;AAGZ;"}
@@ -6,4 +6,4 @@ export interface TimeElementEditorProps {
6
6
  getValue: () => string;
7
7
  }>;
8
8
  }
9
- export declare function TimeElementEditor({ name, element, ref, }: TimeElementEditorProps): import("react").JSX.Element;
9
+ export declare function TimeElementEditor({ name, element, ref, }: TimeElementEditorProps): import("react/jsx-runtime").JSX.Element;
@@ -3,4 +3,4 @@ export interface NumericVariablePickerProps {
3
3
  element: NumberElement | PluralElement;
4
4
  onUpdate: (value: string) => void;
5
5
  }
6
- export declare function NumericVariablePicker({ element, onUpdate, }: NumericVariablePickerProps): import("react").JSX.Element;
6
+ export declare function NumericVariablePicker({ element, onUpdate, }: NumericVariablePickerProps): import("react/jsx-runtime").JSX.Element;