sveltekit-ui 1.1.17 → 1.1.18
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/Components/Alert/index.svelte +88 -0
- package/dist/Components/Alert/index.svelte.js +101 -0
- package/dist/Components/ArrowToggle/index.svelte +62 -0
- package/dist/Components/Attachment/index.svelte +77 -0
- package/dist/Components/Attachment/index.svelte.js +119 -0
- package/dist/Components/Audio/index.svelte +193 -0
- package/dist/Components/Audio/index.svelte.js +463 -0
- package/dist/Components/AudioEditor/index.svelte +252 -0
- package/dist/Components/AudioEditor/index.svelte.js +977 -0
- package/dist/Components/AudioEditor/samples/alloy-voice-sample.mp3 +0 -0
- package/dist/Components/AudioEditor/samples/echo-voice-sample.mp3 +0 -0
- package/dist/Components/AudioEditor/samples/fable-voice-sample.mp3 +0 -0
- package/dist/Components/AudioEditor/samples/nova-voice-sample.mp3 +0 -0
- package/dist/Components/AudioEditor/samples/onyx-voice-sample.mp3 +0 -0
- package/dist/Components/AudioEditor/samples/shimmer-voice-sample.mp3 +0 -0
- package/dist/Components/AuthCodeInput/index.svelte +85 -0
- package/dist/Components/AuthCodeInput/index.svelte.js +95 -0
- package/dist/Components/Breadcrumbs/index.svelte +27 -0
- package/dist/Components/Breadcrumbs/index.svelte.js +88 -0
- package/dist/Components/Button/index.svelte +721 -0
- package/dist/Components/Button/index.svelte.js +375 -0
- package/dist/Components/Chart/Klines/index.svelte +87 -0
- package/dist/Components/Chart/index.svelte +226 -0
- package/dist/Components/Chart/index.svelte.js +1090 -0
- package/dist/Components/ChartInput/DisplayNav/Klines/index.svelte +150 -0
- package/dist/Components/ChartInput/DisplayNav/Lines/index.svelte +45 -0
- package/dist/Components/ChartInput/DisplayNav/index.svelte +297 -0
- package/dist/Components/ChartInput/EditPanel/index.svelte +155 -0
- package/dist/Components/ChartInput/index.svelte +21 -0
- package/dist/Components/ChartInput/index.svelte.js +671 -0
- package/dist/Components/Checkbox/index.svelte +411 -0
- package/dist/Components/Checkbox/index.svelte.js +178 -0
- package/dist/Components/Code/index.svelte +23 -0
- package/dist/Components/Code/index.svelte.js +33 -0
- package/dist/Components/Color/index.svelte +51 -0
- package/dist/Components/Color/index.svelte.js +31 -0
- package/dist/Components/ColorInput/ChromaPicker/index.svelte +50 -0
- package/dist/Components/ColorInput/ColorPalette/index.svelte +62 -0
- package/dist/Components/ColorInput/OpacityPicker/index.svelte +68 -0
- package/dist/Components/ColorInput/ShowcasePicker/index.svelte +136 -0
- package/dist/Components/ColorInput/index.svelte +70 -0
- package/dist/Components/ColorInput/index.svelte.js +386 -0
- package/dist/Components/ConditionsInput/index.svelte +46 -0
- package/dist/Components/ConditionsInput/index.svelte.js +201 -0
- package/dist/Components/Confetti/index.svelte +98 -0
- package/dist/Components/Confetti/index.svelte.js +94 -0
- package/dist/Components/Content/index.svelte +500 -0
- package/dist/Components/Content/index.svelte.js +910 -0
- package/dist/Components/ContentInput/AttributesInput/CustomConfig/Audio/index.svelte +31 -0
- package/dist/Components/ContentInput/AttributesInput/CustomConfig/Audio/index.svelte.js +258 -0
- package/dist/Components/ContentInput/AttributesInput/CustomConfig/AudioAdvanced/index.svelte +31 -0
- package/dist/Components/ContentInput/AttributesInput/CustomConfig/AudioAdvanced/index.svelte.js +258 -0
- package/dist/Components/ContentInput/AttributesInput/CustomConfig/Dropdown/index.svelte +58 -0
- package/dist/Components/ContentInput/AttributesInput/CustomConfig/Dropdown/index.svelte.js +206 -0
- package/dist/Components/ContentInput/AttributesInput/CustomConfig/Image/index.svelte +28 -0
- package/dist/Components/ContentInput/AttributesInput/CustomConfig/Image/index.svelte.js +224 -0
- package/dist/Components/ContentInput/AttributesInput/CustomConfig/Number/index.svelte +44 -0
- package/dist/Components/ContentInput/AttributesInput/CustomConfig/Number/index.svelte.js +272 -0
- package/dist/Components/ContentInput/AttributesInput/CustomConfig/Qr/index.svelte +41 -0
- package/dist/Components/ContentInput/AttributesInput/CustomConfig/Qr/index.svelte.js +202 -0
- package/dist/Components/ContentInput/AttributesInput/CustomConfig/Slider/index.svelte +19 -0
- package/dist/Components/ContentInput/AttributesInput/CustomConfig/Slider/index.svelte.js +117 -0
- package/dist/Components/ContentInput/AttributesInput/CustomConfig/TableAdvanced/index.svelte +60 -0
- package/dist/Components/ContentInput/AttributesInput/CustomConfig/TableAdvanced/index.svelte.js +542 -0
- package/dist/Components/ContentInput/AttributesInput/CustomConfig/Tag/index.svelte +47 -0
- package/dist/Components/ContentInput/AttributesInput/CustomConfig/Tag/index.svelte.js +185 -0
- package/dist/Components/ContentInput/AttributesInput/CustomConfig/TextInput/index.svelte +35 -0
- package/dist/Components/ContentInput/AttributesInput/CustomConfig/TextInput/index.svelte.js +222 -0
- package/dist/Components/ContentInput/AttributesInput/CustomConfig/TimeInput/index.svelte +20 -0
- package/dist/Components/ContentInput/AttributesInput/CustomConfig/TimeInput/index.svelte.js +84 -0
- package/dist/Components/ContentInput/AttributesInput/DefinedTypeInput/index.svelte +25 -0
- package/dist/Components/ContentInput/AttributesInput/DefinedTypeInput/index.svelte.js +91 -0
- package/dist/Components/ContentInput/AttributesInput/index.svelte +352 -0
- package/dist/Components/ContentInput/AttributesInput/index.svelte.js +1436 -0
- package/dist/Components/ContentInput/ContentPanelBuilder/AddElement/index.svelte +64 -0
- package/dist/Components/ContentInput/ContentPanelBuilder/AddElement/index.svelte.js +97 -0
- package/dist/Components/ContentInput/ContentPanelBuilder/ElementList/index.svelte +184 -0
- package/dist/Components/ContentInput/ContentPanelBuilder/index.svelte +41 -0
- package/dist/Components/ContentInput/index.svelte +78 -0
- package/dist/Components/ContentInput/index.svelte.js +1197 -0
- package/dist/Components/CronInput/index.svelte +78 -0
- package/dist/Components/CronInput/index.svelte.js +198 -0
- package/dist/Components/DataTypeInput/index.svelte +174 -0
- package/dist/Components/DataTypeInput/index.svelte.js +565 -0
- package/dist/Components/Dropdown/index.svelte +116 -0
- package/dist/Components/Dropdown/index.svelte.js +403 -0
- package/dist/Components/EmailAddress/index.svelte +22 -0
- package/dist/Components/EmailAddress/index.svelte.js +45 -0
- package/dist/Components/ErrorX/index.svelte +58 -0
- package/dist/Components/Eye/index.svelte +57 -0
- package/dist/Components/FileInput/index.svelte +146 -0
- package/dist/Components/FileInput/index.svelte.js +225 -0
- package/dist/Components/Hamburger/index.svelte +99 -0
- package/dist/Components/HorizScrollBox/index.svelte +145 -0
- package/dist/Components/Icon/index.svelte +412 -0
- package/dist/Components/Icon/index.svelte.js +116 -0
- package/dist/Components/IconInput/index.svelte +77 -0
- package/dist/Components/IconInput/index.svelte.js +259 -0
- package/dist/Components/Image/index.svelte +126 -0
- package/dist/Components/Image/index.svelte.js +116 -0
- package/dist/Components/ImageEditor/Image/CropBox/index.svelte +165 -0
- package/dist/Components/ImageEditor/Image/index.svelte +104 -0
- package/dist/Components/ImageEditor/Panels/AI/index.svelte +44 -0
- package/dist/Components/ImageEditor/Panels/Crop/index.svelte +96 -0
- package/dist/Components/ImageEditor/Panels/File/QualityPicker/index.svelte +124 -0
- package/dist/Components/ImageEditor/Panels/File/index.svelte +74 -0
- package/dist/Components/ImageEditor/Panels/Filters/index.svelte +46 -0
- package/dist/Components/ImageEditor/Panels/Resize/index.svelte +58 -0
- package/dist/Components/ImageEditor/index.svelte +93 -0
- package/dist/Components/ImageEditor/index.svelte.js +1961 -0
- package/dist/Components/ImageSlider/index.svelte +124 -0
- package/dist/Components/ImageSlider/index.svelte.js +99 -0
- package/dist/Components/InfoBox/index.svelte +89 -0
- package/dist/Components/Json/Nested/index.svelte +157 -0
- package/dist/Components/Json/index.svelte +60 -0
- package/dist/Components/Json/index.svelte.js +594 -0
- package/dist/Components/LabeledItem/index.svelte +102 -0
- package/dist/Components/Layout/NavBar/FullNav/index.svelte +52 -0
- package/dist/Components/Layout/NavBar/NavGuts/index.svelte +87 -0
- package/dist/Components/Layout/NavBar/index.svelte +72 -0
- package/dist/Components/Layout/index.svelte +149 -0
- package/dist/Components/Layout/index.svelte.js +360 -0
- package/dist/Components/Link/index.svelte +47 -0
- package/dist/Components/Link/index.svelte.js +136 -0
- package/dist/Components/LoadingSuccessDiv/index.svelte +51 -0
- package/dist/Components/LoadingWheel/index.svelte +38 -0
- package/dist/Components/Location/index.svelte +79 -0
- package/dist/Components/Location/index.svelte.js +288 -0
- package/dist/Components/LocationInput/index.svelte +197 -0
- package/dist/Components/LocationInput/index.svelte.js +965 -0
- package/dist/Components/Number/index.svelte +47 -0
- package/dist/Components/Number/index.svelte.js +151 -0
- package/dist/Components/PhoneCountryCode/index.svelte +7 -0
- package/dist/Components/PhoneCountryCode/index.svelte.js +260 -0
- package/dist/Components/PhoneNumber/index.svelte +22 -0
- package/dist/Components/PhoneNumber/index.svelte.js +41 -0
- package/dist/Components/Popover/index.svelte +396 -0
- package/dist/Components/Popover/index.svelte.js +319 -0
- package/dist/Components/Qr/index.svelte +85 -0
- package/dist/Components/Qr/index.svelte.js +301 -0
- package/dist/Components/QrInput/index.svelte +47 -0
- package/dist/Components/QrInput/index.svelte.js +218 -0
- package/dist/Components/Slider/index.svelte +239 -0
- package/dist/Components/Slider/index.svelte.js +469 -0
- package/dist/Components/Spacer/index.svelte +41 -0
- package/dist/Components/StoragePicker/DisplayFile/index.svelte +15 -0
- package/dist/Components/StoragePicker/index.svelte +187 -0
- package/dist/Components/StoragePicker/index.svelte.js +592 -0
- package/dist/Components/SuccessCheck/index.svelte +56 -0
- package/dist/Components/TableAdvanced/ColumnInput/index.svelte +117 -0
- package/dist/Components/TableAdvanced/ColumnInput/index.svelte.js +456 -0
- package/dist/Components/TableAdvanced/FilterInput/index.svelte +54 -0
- package/dist/Components/TableAdvanced/FilterInput/index.svelte.js +247 -0
- package/dist/Components/TableAdvanced/Pagination/index.svelte +43 -0
- package/dist/Components/TableAdvanced/Pagination/index.svelte.js +97 -0
- package/dist/Components/TableAdvanced/SortByInput/index.svelte +72 -0
- package/dist/Components/TableAdvanced/SortByInput/index.svelte.js +176 -0
- package/dist/Components/TableAdvanced/index.svelte +275 -0
- package/dist/Components/TableAdvanced/index.svelte.js +1565 -0
- package/dist/Components/Tag/index.svelte +45 -0
- package/dist/Components/Tag/index.svelte.js +76 -0
- package/dist/Components/TextArrayInput/index.svelte +108 -0
- package/dist/Components/TextArrayInput/index.svelte.js +239 -0
- package/dist/Components/TextInput/PasswordTooltip/index.svelte +89 -0
- package/dist/Components/TextInput/index.svelte +223 -0
- package/dist/Components/TextInput/index.svelte.js +447 -0
- package/dist/Components/Time/index.svelte +7 -0
- package/dist/Components/Time/index.svelte.js +38 -0
- package/dist/Components/TimeInput/NumberToggler/index.svelte +34 -0
- package/dist/Components/TimeInput/NumberToggler/index.svelte.js +79 -0
- package/dist/Components/TimeInput/index.js +702 -0
- package/dist/Components/TimeInput/index.svelte +211 -0
- package/dist/Components/TimeInput/index.svelte.js +638 -0
- package/dist/Components/Tooltip/index.svelte +143 -0
- package/dist/Components/TransparentBackground/index.svelte +153 -0
- package/dist/Components/TypingDots/index.svelte +84 -0
- package/dist/Components/VariablePathInput/index.svelte +63 -0
- package/dist/Components/VariablePathInput/index.svelte.js +273 -0
- package/dist/Components/VideoTBD/index.svelte +100 -0
- package/dist/Components/XFollow/index.svelte +42 -0
- package/dist/Components/XPost/index.svelte +52 -0
- package/dist/Components/XPost/index.svelte.js +64 -0
- package/dist/Components/YoutubeChannelButton/index.svelte +82 -0
- package/dist/Components/YoutubeVideo/index.svelte +73 -0
- package/dist/Components/YoutubeVideo/index.svelte.js +54 -0
- package/dist/actions/draggable.js +49 -0
- package/dist/actions/index.js +24 -0
- package/dist/actions/no_spaces.js +33 -0
- package/dist/actions/numbers_only.js +26 -0
- package/dist/actions/scroll_y.js +28 -0
- package/dist/actions/stop_scroll_propagation_y.js +42 -0
- package/dist/actions/swipe_handler.js +295 -0
- package/dist/client/astc_formatting/index.js +1128 -0
- package/dist/client/docs/index.js +7622 -0
- package/dist/client/index.js +735 -0
- package/dist/client/types/index.js +2812 -0
- package/dist/index.js +180 -0
- package/dist/style.css +682 -0
- package/package.json +1 -1
|
@@ -0,0 +1,1128 @@
|
|
|
1
|
+
import { create_unique_id, deep_copy, time_zone_options, language_options } from "../index.js"
|
|
2
|
+
|
|
3
|
+
export function astc_element(type_id, children = [], attrs = {}) {
|
|
4
|
+
return {
|
|
5
|
+
type_id: type_id,
|
|
6
|
+
selector_id: create_unique_id(null, 8),
|
|
7
|
+
children: children,
|
|
8
|
+
attributes: attrs,
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
function process_line(match_groups, interline_astc_children, previous_base_text) {
|
|
13
|
+
const { strong, em, strong_em, code_inline, link, image, base_text } = match_groups
|
|
14
|
+
if (strong_em || strong || em || code_inline || link || image) {
|
|
15
|
+
if (previous_base_text) {
|
|
16
|
+
interline_astc_children.push(astc_element("base_text", [], { content: previous_base_text }))
|
|
17
|
+
previous_base_text = ""
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
if (strong_em) {
|
|
21
|
+
interline_astc_children.push(astc_element("strong_em", [], { content: strong_em.slice(3, -3) }))
|
|
22
|
+
} else if (strong) {
|
|
23
|
+
interline_astc_children.push(astc_element("strong", [], { content: strong.slice(2, -2) }))
|
|
24
|
+
} else if (em) {
|
|
25
|
+
interline_astc_children.push(astc_element("em", [], { content: em.slice(1, -1) }))
|
|
26
|
+
} else if (code_inline) {
|
|
27
|
+
interline_astc_children.push(astc_element("code_inline", [], { content: code_inline.slice(1, -1) }))
|
|
28
|
+
} else if (link) {
|
|
29
|
+
const name_match = link.match(/^\[(.*?)\]/)
|
|
30
|
+
const href_match = link.match(/\((.*?)\)$/)
|
|
31
|
+
const name = name_match ? name_match[1] : ""
|
|
32
|
+
const href = href_match ? href_match[1] : ""
|
|
33
|
+
interline_astc_children.push(astc_element("a", [], { content: name, href: href }))
|
|
34
|
+
} else if (image) {
|
|
35
|
+
const alt_match = image.match(/^!\[(.*?)\]/)
|
|
36
|
+
const src_match = image.match(/\((.*?)\)$/)
|
|
37
|
+
const alt = alt_match ? alt_match[1] : ""
|
|
38
|
+
const src = src_match ? src_match[1] : ""
|
|
39
|
+
interline_astc_children.push(astc_element("img", [], { alt: alt, src: src }))
|
|
40
|
+
} else if (base_text) {
|
|
41
|
+
previous_base_text += base_text
|
|
42
|
+
} else {
|
|
43
|
+
previous_base_text += " "
|
|
44
|
+
}
|
|
45
|
+
return previous_base_text
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
function sub_list_to_astc_children(assembled_lines) {
|
|
49
|
+
let lists_astc = []
|
|
50
|
+
let list_type = assembled_lines?.[0]?.type
|
|
51
|
+
let list_astc_children = []
|
|
52
|
+
let subgroup = []
|
|
53
|
+
let assembled_lines_to_use = [...assembled_lines, { type: "END", level: -1, val: null }]
|
|
54
|
+
for (let assem_line of assembled_lines_to_use) {
|
|
55
|
+
if (assem_line?.level < 1) {
|
|
56
|
+
if (subgroup.length > 0) {
|
|
57
|
+
const sublist_astc_children = sub_list_to_astc_children(subgroup)
|
|
58
|
+
list_astc_children.push(...sublist_astc_children)
|
|
59
|
+
subgroup = []
|
|
60
|
+
}
|
|
61
|
+
if (list_type != assem_line?.type) {
|
|
62
|
+
lists_astc.push(astc_element(list_type, list_astc_children))
|
|
63
|
+
list_astc_children = []
|
|
64
|
+
list_type = assem_line?.type
|
|
65
|
+
}
|
|
66
|
+
list_astc_children.push(astc_element("li", markdown_to_astc_children(assem_line?.val)))
|
|
67
|
+
} else {
|
|
68
|
+
subgroup.push({
|
|
69
|
+
type: assem_line?.type,
|
|
70
|
+
level: assem_line?.level - 1,
|
|
71
|
+
val: assem_line?.val,
|
|
72
|
+
})
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
return lists_astc
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
function markdown_to_astc_children(markdown, base_text_wrapper_type = null) {
|
|
79
|
+
let astc_children = []
|
|
80
|
+
let assembled_lines = []
|
|
81
|
+
let currently_in_type = null
|
|
82
|
+
markdown += "\nEND00END"
|
|
83
|
+
for (let line of markdown.split(/[\n]+/)) {
|
|
84
|
+
if (currently_in_type) {
|
|
85
|
+
if (currently_in_type == "code" && line.trim().startsWith("```")) {
|
|
86
|
+
//end of code
|
|
87
|
+
let language
|
|
88
|
+
let code_lines = []
|
|
89
|
+
for (let assem_line of assembled_lines) {
|
|
90
|
+
if (assem_line?.type == "language") {
|
|
91
|
+
language = assem_line?.val
|
|
92
|
+
} else {
|
|
93
|
+
code_lines.push(assem_line?.val)
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
const code_markdown = code_lines.join("\n")
|
|
97
|
+
astc_children.push(astc_element("code", [], { content: code_markdown, language: language }))
|
|
98
|
+
assembled_lines = []
|
|
99
|
+
currently_in_type = null
|
|
100
|
+
line = line.trim().slice(3)
|
|
101
|
+
} else if (currently_in_type == "table" && !line.trim().startsWith("|")) {
|
|
102
|
+
// end of table
|
|
103
|
+
let thead_children = []
|
|
104
|
+
let tbody_children = []
|
|
105
|
+
for (let row of assembled_lines) {
|
|
106
|
+
if (["thead", "tbody"].includes(row?.type)) {
|
|
107
|
+
let tr_children = []
|
|
108
|
+
const regex = /\|\s*([^|]*?)(?=\s*\||$)/g
|
|
109
|
+
const matches = Array.from(row?.val.matchAll(regex))
|
|
110
|
+
const columns = matches ? matches.map((match) => match[1].trim()).filter((column) => column !== "") : []
|
|
111
|
+
if (row.type == "thead") {
|
|
112
|
+
for (let column of columns) {
|
|
113
|
+
tr_children.push(astc_element("th", markdown_to_astc_children(column)))
|
|
114
|
+
}
|
|
115
|
+
thead_children.push(astc_element("tr", tr_children))
|
|
116
|
+
} else if (row.type == "tbody") {
|
|
117
|
+
for (let column of columns) {
|
|
118
|
+
tr_children.push(astc_element("td", markdown_to_astc_children(column)))
|
|
119
|
+
}
|
|
120
|
+
tbody_children.push(astc_element("tr", tr_children))
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
const astc_thead = astc_element("thead", thead_children)
|
|
125
|
+
const astc_tbody = astc_element("tbody", tbody_children)
|
|
126
|
+
const astc_table = astc_element("table", [astc_thead, astc_tbody])
|
|
127
|
+
astc_children.push(astc_table)
|
|
128
|
+
assembled_lines = []
|
|
129
|
+
currently_in_type = null
|
|
130
|
+
} else if (
|
|
131
|
+
currently_in_type == "list" &&
|
|
132
|
+
!(line.match(/^\s*\d+\./) || line.trim().startsWith("- ") || line.trim().startsWith("* "))
|
|
133
|
+
) {
|
|
134
|
+
//end of list
|
|
135
|
+
let level_options = []
|
|
136
|
+
for (let assembled_line of assembled_lines) {
|
|
137
|
+
if (!level_options.includes(assembled_line?.level)) {
|
|
138
|
+
level_options.push(assembled_line?.level)
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
const sorted_levels = level_options.sort((a, b) => a - b)
|
|
142
|
+
let clean_level_assembled_lines = []
|
|
143
|
+
for (let assembled_line of assembled_lines) {
|
|
144
|
+
const simple_level = sorted_levels.findIndex((h) => h == assembled_line?.level)
|
|
145
|
+
clean_level_assembled_lines.push({
|
|
146
|
+
type: assembled_line?.type,
|
|
147
|
+
level: simple_level,
|
|
148
|
+
val: assembled_line?.val,
|
|
149
|
+
})
|
|
150
|
+
}
|
|
151
|
+
const list_astc_children = sub_list_to_astc_children(clean_level_assembled_lines)
|
|
152
|
+
astc_children.push(...list_astc_children)
|
|
153
|
+
assembled_lines = []
|
|
154
|
+
currently_in_type = null
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
if (currently_in_type == "code" || line.trim().startsWith("```")) {
|
|
158
|
+
//start of code
|
|
159
|
+
if (currently_in_type != "code" && line.trim().startsWith("```")) {
|
|
160
|
+
const intro_row = line.trim().slice(3)
|
|
161
|
+
if (intro_row.length > 0) {
|
|
162
|
+
assembled_lines.push({ type: "language", val: intro_row })
|
|
163
|
+
}
|
|
164
|
+
currently_in_type = "code"
|
|
165
|
+
} else {
|
|
166
|
+
assembled_lines.push({ type: "code", val: line })
|
|
167
|
+
}
|
|
168
|
+
} else if (line.startsWith(">")) {
|
|
169
|
+
//line is blockquote
|
|
170
|
+
const blockquote_astc_children = markdown_to_astc_children(line.trim().slice(1).trim())
|
|
171
|
+
astc_children.push(
|
|
172
|
+
astc_element("figure", [astc_element("blockquote", blockquote_astc_children, { cite: null })], {
|
|
173
|
+
caption: null,
|
|
174
|
+
})
|
|
175
|
+
)
|
|
176
|
+
} else if (line.trim().startsWith("|")) {
|
|
177
|
+
//start of table
|
|
178
|
+
currently_in_type = "table"
|
|
179
|
+
if (/^\|\s?(:?-{2})/.test(line.trim())) {
|
|
180
|
+
assembled_lines.push({ type: "divider" })
|
|
181
|
+
} else {
|
|
182
|
+
const type = assembled_lines.some((h) => h.type == "divider") ? "tbody" : "thead"
|
|
183
|
+
assembled_lines.push({ type: type, val: line })
|
|
184
|
+
}
|
|
185
|
+
} else if (line.match(/^\s*\d+\./) || line.trim().startsWith("- ") || line.trim().startsWith("* ")) {
|
|
186
|
+
//start of list
|
|
187
|
+
currently_in_type = "list"
|
|
188
|
+
let is_ul = line.trim().startsWith("- ") || line.trim().startsWith("* ")
|
|
189
|
+
const level = line.match(/^ */)[0].length
|
|
190
|
+
if (is_ul) {
|
|
191
|
+
assembled_lines.push({
|
|
192
|
+
type: "ul",
|
|
193
|
+
level: level,
|
|
194
|
+
val: line.trim().slice(2),
|
|
195
|
+
})
|
|
196
|
+
} else {
|
|
197
|
+
assembled_lines.push({
|
|
198
|
+
type: "ol",
|
|
199
|
+
level: level,
|
|
200
|
+
val: line.match(/^\s*\d+\.\s*(.*)/)[1],
|
|
201
|
+
})
|
|
202
|
+
}
|
|
203
|
+
} else if (line.match(/^#+/)) {
|
|
204
|
+
// heading
|
|
205
|
+
const heading_match = line.match(/^#+/)
|
|
206
|
+
const heading_level = heading_match[0].length
|
|
207
|
+
const markdown_remaining = line.slice(heading_level).trimStart()
|
|
208
|
+
let heading_astc = astc_element(`h${heading_level}`, markdown_to_astc_children(markdown_remaining))
|
|
209
|
+
astc_children.push(heading_astc)
|
|
210
|
+
} else if (line.startsWith("---")) {
|
|
211
|
+
// horiz rule
|
|
212
|
+
astc_children.push(astc_element("hr"))
|
|
213
|
+
} else if (!line.startsWith("END00END")) {
|
|
214
|
+
let interline_astc_children = []
|
|
215
|
+
const regex =
|
|
216
|
+
/(?<strong_em>\*\*\*[^*]+\*\*\*|___[^_]+___)|(?<strong>\*\*[^*]+\*\*|__[^_]+__)|(?<em>\*[^*]+\*|_[^_]+_)|(?<code_inline>`[^`]+`)|(?<link>\[.*?\]\(.*?\))|(?<img>!\[.*?\]\(.*?\))|(?<base_text>[^\s*_`[\]]+)|\s+/g
|
|
217
|
+
const matches = Array.from(line.matchAll(regex))
|
|
218
|
+
let previous_base_text = ""
|
|
219
|
+
for (let match of matches) {
|
|
220
|
+
previous_base_text = process_line(match.groups, interline_astc_children, previous_base_text)
|
|
221
|
+
}
|
|
222
|
+
process_base_text()
|
|
223
|
+
function process_base_text() {
|
|
224
|
+
if (previous_base_text) {
|
|
225
|
+
interline_astc_children.push(astc_element("base_text", [], { content: previous_base_text }))
|
|
226
|
+
previous_base_text = ""
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
if (base_text_wrapper_type) {
|
|
230
|
+
astc_children.push(astc_element(base_text_wrapper_type, interline_astc_children))
|
|
231
|
+
} else {
|
|
232
|
+
astc_children.push(...interline_astc_children)
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
return astc_children
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
export function markdown_to_astc(markdown) {
|
|
240
|
+
const astc_children = markdown_to_astc_children(markdown, "p")
|
|
241
|
+
return {
|
|
242
|
+
type_id: "div",
|
|
243
|
+
children: astc_children,
|
|
244
|
+
attributes: {},
|
|
245
|
+
selector_id: create_unique_id(null, 8),
|
|
246
|
+
}
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
export function astc_to_markdown(astc) {
|
|
250
|
+
function process_children(children, parent, level = 0) {
|
|
251
|
+
return children.map((child, index) => astc_element_to_markdown(child, parent, level, index)).join("")
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
function get_table_divider_row(thead_children) {
|
|
255
|
+
const divider_cells = thead_children[0].children.map((th) => {
|
|
256
|
+
const content_length = th.children.map((child) => child.attributes.content.length).reduce((a, b) => a + b, 0)
|
|
257
|
+
return "-".repeat(content_length)
|
|
258
|
+
})
|
|
259
|
+
return "| " + divider_cells.join(" | ") + " |"
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
function astc_element_to_markdown(element, parent = null, level = 0, index = 0) {
|
|
263
|
+
const { type_id, children, attributes } = element
|
|
264
|
+
switch (type_id) {
|
|
265
|
+
case "h1":
|
|
266
|
+
case "h2":
|
|
267
|
+
case "h3":
|
|
268
|
+
case "h4":
|
|
269
|
+
case "h5":
|
|
270
|
+
case "h6":
|
|
271
|
+
const heading_level = parseInt(type_id.slice(1))
|
|
272
|
+
return `${"#".repeat(heading_level)} ${process_children(children)}\n`
|
|
273
|
+
case "section":
|
|
274
|
+
case "div":
|
|
275
|
+
case "p":
|
|
276
|
+
case "footer":
|
|
277
|
+
return `${process_children(children)}\n`
|
|
278
|
+
case "strong":
|
|
279
|
+
return `**${attributes.content}**`
|
|
280
|
+
case "em":
|
|
281
|
+
return `*${attributes.content}*`
|
|
282
|
+
case "strong_em":
|
|
283
|
+
return `***${attributes.content}***`
|
|
284
|
+
case "code_inline":
|
|
285
|
+
return `\`${attributes.content}\``
|
|
286
|
+
case "a":
|
|
287
|
+
case "ref":
|
|
288
|
+
return `[${attributes.content ?? attributes.href}](${attributes.href})`
|
|
289
|
+
case "img":
|
|
290
|
+
return `\n`
|
|
291
|
+
case "ul":
|
|
292
|
+
case "ol":
|
|
293
|
+
return children.map((child, index) => astc_element_to_markdown(child, element, level + 1, index)).join("\n")
|
|
294
|
+
case "li":
|
|
295
|
+
const list_item_prefix = parent && parent.type_id === "ol" ? `${index + 1}. ` : "- "
|
|
296
|
+
const indent = " ".repeat(Math.max(0, level - 1))
|
|
297
|
+
return `${indent}${list_item_prefix}${process_children(children, element, level)}`
|
|
298
|
+
case "figure":
|
|
299
|
+
if (attributes.caption) {
|
|
300
|
+
return `> ${process_children(children)}\n> —${attributes.caption}\n`
|
|
301
|
+
} else {
|
|
302
|
+
return `> ${process_children(children)}\n`
|
|
303
|
+
}
|
|
304
|
+
case "code":
|
|
305
|
+
const language = attributes.language ? attributes.language : ""
|
|
306
|
+
return `\`\`\`${language}\n${attributes.content}\n\`\`\`\n`
|
|
307
|
+
case "hr":
|
|
308
|
+
return "---\n"
|
|
309
|
+
case "br":
|
|
310
|
+
return "\n"
|
|
311
|
+
case "table":
|
|
312
|
+
const table_rows = children.map((child) => astc_element_to_markdown(child))
|
|
313
|
+
return table_rows.join("\n") + "\n"
|
|
314
|
+
case "thead":
|
|
315
|
+
const header_rows = children.map((child) => astc_element_to_markdown(child))
|
|
316
|
+
const divider_row = get_table_divider_row(children)
|
|
317
|
+
return header_rows.join("\n") + "\n" + divider_row
|
|
318
|
+
case "tbody":
|
|
319
|
+
const rows = children.map((child) => astc_element_to_markdown(child))
|
|
320
|
+
return rows.join("\n")
|
|
321
|
+
case "tr":
|
|
322
|
+
const cells = children.map((child) => astc_element_to_markdown(child))
|
|
323
|
+
return `| ${cells.join(" | ")} |`
|
|
324
|
+
case "th":
|
|
325
|
+
case "td":
|
|
326
|
+
return process_children(children)
|
|
327
|
+
case "base_text":
|
|
328
|
+
return attributes.content
|
|
329
|
+
default:
|
|
330
|
+
return ""
|
|
331
|
+
}
|
|
332
|
+
}
|
|
333
|
+
return astc_element_to_markdown(astc)
|
|
334
|
+
}
|
|
335
|
+
|
|
336
|
+
export function get_variable_from_path(path, variables, defs) {
|
|
337
|
+
if (Array.isArray(path)) {
|
|
338
|
+
let combined_variables_loc = deep_copy({
|
|
339
|
+
variables: variables,
|
|
340
|
+
defs: defs,
|
|
341
|
+
})
|
|
342
|
+
for (let path_item of path) {
|
|
343
|
+
if (Array.isArray(path_item)) {
|
|
344
|
+
let sub_val_from_path = get_variable_from_path(path_item)
|
|
345
|
+
combined_variables_loc = combined_variables_loc?.[sub_val_from_path]
|
|
346
|
+
} else {
|
|
347
|
+
combined_variables_loc = combined_variables_loc?.[path_item]
|
|
348
|
+
}
|
|
349
|
+
}
|
|
350
|
+
return combined_variables_loc
|
|
351
|
+
}
|
|
352
|
+
return null
|
|
353
|
+
}
|
|
354
|
+
|
|
355
|
+
export function clean_variable_path(path, variables, defs) {
|
|
356
|
+
// eg. ['variables','dddd',['defs',0]] to ['variables','dddd',3]
|
|
357
|
+
if (Array.isArray(path)) {
|
|
358
|
+
let cleaned_path = []
|
|
359
|
+
for (let path_item of path) {
|
|
360
|
+
if (Array.isArray(path_item)) {
|
|
361
|
+
let sub_val_from_path = get_variable_from_path(path_item, variables, defs)
|
|
362
|
+
cleaned_path.push(sub_val_from_path)
|
|
363
|
+
} else {
|
|
364
|
+
cleaned_path.push(path_item)
|
|
365
|
+
}
|
|
366
|
+
}
|
|
367
|
+
return cleaned_path
|
|
368
|
+
}
|
|
369
|
+
return null
|
|
370
|
+
}
|
|
371
|
+
|
|
372
|
+
export function clean_attributes_from_variable_path(attributes, variables, defs) {
|
|
373
|
+
let cleaned_attributes = attributes
|
|
374
|
+
if (Object.keys(attributes || {}).length) {
|
|
375
|
+
for (let [att_key, att_val] of Object.entries(attributes)) {
|
|
376
|
+
if (att_key.endsWith("_from_variable_path") && att_val != null) {
|
|
377
|
+
const clean_path = clean_variable_path(att_val, variables, defs)
|
|
378
|
+
const att_key_to_set = att_key.split("_from_variable_path")?.[0]
|
|
379
|
+
cleaned_attributes[att_key_to_set] = get_variable_from_path(clean_path, variables, defs)
|
|
380
|
+
delete cleaned_attributes[att_key]
|
|
381
|
+
}
|
|
382
|
+
}
|
|
383
|
+
}
|
|
384
|
+
return cleaned_attributes
|
|
385
|
+
}
|
|
386
|
+
|
|
387
|
+
export function astc_to_static_attributes(astc, variables, defs) {
|
|
388
|
+
if ([undefined, null].includes(astc)) {
|
|
389
|
+
return null
|
|
390
|
+
}
|
|
391
|
+
let astc_loc = deep_copy(astc)
|
|
392
|
+
if (Object.keys(astc_loc?.attributes || {}).length > 0) {
|
|
393
|
+
astc_loc.attributes = clean_attributes_from_variable_path(astc_loc?.attributes, variables, defs)
|
|
394
|
+
}
|
|
395
|
+
if (Array.isArray(astc_loc?.children)) {
|
|
396
|
+
let cleaned_children = []
|
|
397
|
+
for (let child of astc_loc.children) {
|
|
398
|
+
cleaned_children.push(astc_to_static_attributes(child, variables, defs))
|
|
399
|
+
}
|
|
400
|
+
astc_loc.children = cleaned_children
|
|
401
|
+
}
|
|
402
|
+
return astc_loc
|
|
403
|
+
}
|
|
404
|
+
|
|
405
|
+
export function astc_to_embedding_text(astc) {
|
|
406
|
+
// this needs work tbd
|
|
407
|
+
let embedding_text = ""
|
|
408
|
+
if (astc?.attributes?.content) {
|
|
409
|
+
embedding_text += astc.attributes.content
|
|
410
|
+
} else if (astc?.attributes?.val) {
|
|
411
|
+
embedding_text += astc.attributes.val // tbd like maybe time types get converted to good display content
|
|
412
|
+
}
|
|
413
|
+
if (astc?.children) {
|
|
414
|
+
for (let child of astc.children) {
|
|
415
|
+
let child_text = astc_to_embedding_text(child)
|
|
416
|
+
embedding_text += child_text ? " " + child_text.trim() : ""
|
|
417
|
+
}
|
|
418
|
+
}
|
|
419
|
+
embedding_text = embedding_text.replace(/\n/g, "")
|
|
420
|
+
embedding_text = embedding_text.replace(/\s{2,}/g, " ")
|
|
421
|
+
embedding_text = embedding_text.trim()
|
|
422
|
+
if (embedding_text.length > 0) {
|
|
423
|
+
if (["th", "td"].includes(astc?.type_id)) {
|
|
424
|
+
if (![".", "?", "!"].includes(embedding_text.slice(-1))) {
|
|
425
|
+
embedding_text += "."
|
|
426
|
+
} else {
|
|
427
|
+
embedding_text += " "
|
|
428
|
+
}
|
|
429
|
+
} else {
|
|
430
|
+
// console.log("tbd_astc_to_emb", astc)
|
|
431
|
+
}
|
|
432
|
+
}
|
|
433
|
+
embedding_text = embedding_text.replace(/[^\x00-\x7F]/g, "")
|
|
434
|
+
embedding_text = embedding_text.replace(/"/g, "")
|
|
435
|
+
return embedding_text
|
|
436
|
+
}
|
|
437
|
+
|
|
438
|
+
function hue_to_rgb(p, q, t) {
|
|
439
|
+
if (t < 0) t += 1
|
|
440
|
+
if (t > 1) t -= 1
|
|
441
|
+
if (t < 1 / 6) return p + (q - p) * 6 * t
|
|
442
|
+
if (t < 1 / 2) return q
|
|
443
|
+
if (t < 2 / 3) return p + (q - p) * (2 / 3 - t) * 6
|
|
444
|
+
return p
|
|
445
|
+
}
|
|
446
|
+
|
|
447
|
+
export function hcl_to_hex(h, c, l) {
|
|
448
|
+
const hues = [
|
|
449
|
+
345, 360, 10, 20, 30, 45, 55, 70, 85, 100, 120, 140, 155, 170, 185, 200, 215, 230, 245, 260, 275, 290, 305, 320,
|
|
450
|
+
335,
|
|
451
|
+
]
|
|
452
|
+
h = hues[h]
|
|
453
|
+
c = (100 * c) / 24
|
|
454
|
+
l = (100 * l) / 24
|
|
455
|
+
h /= 360
|
|
456
|
+
c /= 100
|
|
457
|
+
l /= 100
|
|
458
|
+
let r, g, b
|
|
459
|
+
if (c === 0) {
|
|
460
|
+
r = g = b = l
|
|
461
|
+
} else {
|
|
462
|
+
const q = l < 0.5 ? l * (1 + c) : l + c - l * c
|
|
463
|
+
const p = 2 * l - q
|
|
464
|
+
r = hue_to_rgb(p, q, h + 1 / 3)
|
|
465
|
+
g = hue_to_rgb(p, q, h)
|
|
466
|
+
b = hue_to_rgb(p, q, h - 1 / 3)
|
|
467
|
+
}
|
|
468
|
+
r = Math.floor(r * 255)
|
|
469
|
+
.toString(16)
|
|
470
|
+
.padStart(2, "0")
|
|
471
|
+
g = Math.floor(g * 255)
|
|
472
|
+
.toString(16)
|
|
473
|
+
.padStart(2, "0")
|
|
474
|
+
b = Math.floor(b * 255)
|
|
475
|
+
.toString(16)
|
|
476
|
+
.padStart(2, "0")
|
|
477
|
+
return `#${r}${g}${b}`
|
|
478
|
+
}
|
|
479
|
+
|
|
480
|
+
function attribute_to_string(attr_obj) {
|
|
481
|
+
return attr_obj
|
|
482
|
+
? Object.entries(attr_obj || {})
|
|
483
|
+
.filter(([key, value]) => value !== null)
|
|
484
|
+
.map(([key, value]) => `${key}="${value}"`)
|
|
485
|
+
.join(" ")
|
|
486
|
+
: ""
|
|
487
|
+
}
|
|
488
|
+
|
|
489
|
+
export function astc_to_email_html(astc, options, slots_html_and_text_body) {
|
|
490
|
+
function get_src(src, storage_id) {
|
|
491
|
+
let storage_path = options?.storage_path ?? "/api/v1/storage/{storage_id}"
|
|
492
|
+
if (src) {
|
|
493
|
+
return src
|
|
494
|
+
} else if (storage_id && storage_path) {
|
|
495
|
+
return storage_path.replace("{storage_id}", storage_id)
|
|
496
|
+
} else {
|
|
497
|
+
return null
|
|
498
|
+
}
|
|
499
|
+
}
|
|
500
|
+
let font_family = options?.font_family
|
|
501
|
+
let text_color_hex = options?.text_color_hex
|
|
502
|
+
if (["h1", "h2", "h3", "h4", "h5", "h6"].includes(astc?.type_id)) {
|
|
503
|
+
font_family = options?.font_family_serif
|
|
504
|
+
text_color_hex = options?.header_color_hex
|
|
505
|
+
}
|
|
506
|
+
let style_attributes = `font-family: ${font_family}; color: ${text_color_hex};`
|
|
507
|
+
if (astc?.type_id === "table") {
|
|
508
|
+
style_attributes += `border: 1px solid ${text_color_hex}; border-collapse: collapse;`
|
|
509
|
+
} else if (["th", "td"].includes(astc?.type_id)) {
|
|
510
|
+
style_attributes += `border: 1px solid ${text_color_hex}; text-align: left; padding: 8px;`
|
|
511
|
+
} else if (["div"].includes(astc?.type_id)) {
|
|
512
|
+
if (astc?.attributes?.background_color) {
|
|
513
|
+
style_attributes += `background-color: ${astc?.attributes.background_color};`
|
|
514
|
+
}
|
|
515
|
+
if (astc?.attributes?.border_color) {
|
|
516
|
+
style_attributes += `border: 1px solid ${astc?.attributes.border_color};`
|
|
517
|
+
}
|
|
518
|
+
if (astc?.attributes?.border_radius) {
|
|
519
|
+
style_attributes += `border-radius: ${astc?.attributes?.border_radius}rem;`
|
|
520
|
+
}
|
|
521
|
+
if (astc?.attributes?.padding) {
|
|
522
|
+
style_attributes += `padding: ${astc?.attributes?.padding}rem;`
|
|
523
|
+
}
|
|
524
|
+
if (astc?.attributes?.align_content || astc?.attributes?.justify_content) {
|
|
525
|
+
style_attributes += `display: grid; place-content: ${astc?.attributes?.align_content ?? "stretch"} ${
|
|
526
|
+
astc?.attributes?.justify_content ?? "stretch"
|
|
527
|
+
};`
|
|
528
|
+
}
|
|
529
|
+
}
|
|
530
|
+
style_attributes = `style="${style_attributes}"`
|
|
531
|
+
switch (astc?.type_id) {
|
|
532
|
+
case "slot":
|
|
533
|
+
console.log("slot_case", astc, slots_html_and_text_body)
|
|
534
|
+
if (Object.keys(slots_html_and_text_body || {}).includes(astc?.attributes?.val)) {
|
|
535
|
+
console.log("return_slot_html", slots_html_and_text_body?.[astc?.attributes?.val]?.html_body)
|
|
536
|
+
return slots_html_and_text_body?.[astc?.attributes?.val]?.html_body
|
|
537
|
+
}
|
|
538
|
+
case "link": {
|
|
539
|
+
const text = astc.attributes.display_text
|
|
540
|
+
? astc.attributes.display_text
|
|
541
|
+
: (astc.children || []).map((child) => astc_to_email_html(child, options, slots_html_and_text_body)).join("") ||
|
|
542
|
+
astc.attributes.href
|
|
543
|
+
return `<a ${attribute_to_string(astc.attributes)}>
|
|
544
|
+
${text}
|
|
545
|
+
</a>`
|
|
546
|
+
}
|
|
547
|
+
case "h1":
|
|
548
|
+
case "h2":
|
|
549
|
+
case "h3":
|
|
550
|
+
case "h4":
|
|
551
|
+
case "h5":
|
|
552
|
+
case "h6":
|
|
553
|
+
case "section":
|
|
554
|
+
case "div":
|
|
555
|
+
case "p":
|
|
556
|
+
case "footer":
|
|
557
|
+
case "ul":
|
|
558
|
+
case "ol":
|
|
559
|
+
case "li":
|
|
560
|
+
case "table":
|
|
561
|
+
case "thead":
|
|
562
|
+
case "tbody":
|
|
563
|
+
case "tr":
|
|
564
|
+
case "th":
|
|
565
|
+
case "td":
|
|
566
|
+
return `<${astc?.type_id} ${style_attributes} ${attribute_to_string(astc?.attributes)}>${astc?.children
|
|
567
|
+
.map((child) => astc_to_email_html(child, options, slots_html_and_text_body))
|
|
568
|
+
.join("")}</${astc?.type_id}>`
|
|
569
|
+
case "strong":
|
|
570
|
+
return `<strong>${astc?.attributes.content}</strong>`
|
|
571
|
+
case "em":
|
|
572
|
+
return `<em>${astc?.attributes.content}</em>`
|
|
573
|
+
case "strong_em":
|
|
574
|
+
return `<strong><em>${astc?.attributes.content}</em></strong>`
|
|
575
|
+
case "code_inline":
|
|
576
|
+
return `<code>${astc?.attributes.content}</code>`
|
|
577
|
+
case "a":
|
|
578
|
+
return `<a href="${astc?.attributes.href}">${astc?.attributes.content || astc?.attributes.href}</a>`
|
|
579
|
+
case "image": // img tbd
|
|
580
|
+
return `<img style="border-radius: 10px;" width="100%" height="auto" src="${get_src(
|
|
581
|
+
astc?.attributes?.src,
|
|
582
|
+
astc?.attributes?.storage_id
|
|
583
|
+
)}" alt="${astc?.attributes?.alt ?? "unknown"}" ${attribute_to_string(astc?.attributes)} />`
|
|
584
|
+
case "code":
|
|
585
|
+
return `<pre><code ${astc?.attributes?.language ? `class="${astc?.attributes?.language}"` : ""}>${
|
|
586
|
+
astc?.attributes?.content
|
|
587
|
+
}</code></pre>`
|
|
588
|
+
case "figure":
|
|
589
|
+
const caption = astc?.attributes?.caption ? `<figcaption>${astc?.attributes?.caption}</figcaption>` : ""
|
|
590
|
+
return `<figure ${style_attributes} ${attribute_to_string(astc?.attributes)}>${astc?.children
|
|
591
|
+
.map((child) => astc_to_email_html(child, options, slots_html_and_text_body))
|
|
592
|
+
.join("")}${caption}</figure>`
|
|
593
|
+
case "blockquote":
|
|
594
|
+
return `<blockquote cite="${astc?.attributes.cite}">${astc?.children
|
|
595
|
+
.map((child) => astc_to_email_html(child, options, slots_html_and_text_body))
|
|
596
|
+
.join("")}</blockquote>`
|
|
597
|
+
case "hr":
|
|
598
|
+
return `<hr ${attribute_to_string(astc?.attributes)} />`
|
|
599
|
+
case "base_text":
|
|
600
|
+
return astc?.attributes.content
|
|
601
|
+
default:
|
|
602
|
+
return ""
|
|
603
|
+
}
|
|
604
|
+
}
|
|
605
|
+
|
|
606
|
+
export function variables_data_type_remaining_to_astc(
|
|
607
|
+
variables_data_type_remaining,
|
|
608
|
+
preferred_content_use = "display",
|
|
609
|
+
leading_variable_path = []
|
|
610
|
+
) {
|
|
611
|
+
// consider passing in options / attributes like label, min, max, is_nullable, etc
|
|
612
|
+
// dropdown input tbd
|
|
613
|
+
// tag display
|
|
614
|
+
// link
|
|
615
|
+
// file input/display
|
|
616
|
+
// image input/display
|
|
617
|
+
// audio input/display
|
|
618
|
+
// table advanced input/display
|
|
619
|
+
// qr input/display
|
|
620
|
+
// x_post input/display
|
|
621
|
+
// youtube_video input/display
|
|
622
|
+
// video input/display
|
|
623
|
+
if (!variables_data_type_remaining?.type) {
|
|
624
|
+
return null
|
|
625
|
+
} else if (variables_data_type_remaining?.type == "color_literal") {
|
|
626
|
+
if (preferred_content_use == "input") {
|
|
627
|
+
return astc_element("color_input", [], {
|
|
628
|
+
val_from_variable_path: leading_variable_path,
|
|
629
|
+
...(variables_data_type_remaining?.attributes ?? {}),
|
|
630
|
+
})
|
|
631
|
+
}
|
|
632
|
+
return astc_element("color", [], {
|
|
633
|
+
val_from_variable_path: leading_variable_path,
|
|
634
|
+
size: 10,
|
|
635
|
+
...(variables_data_type_remaining?.attributes ?? {}),
|
|
636
|
+
})
|
|
637
|
+
} else if (variables_data_type_remaining?.type == "text_literal") {
|
|
638
|
+
if (preferred_content_use == "input") {
|
|
639
|
+
return astc_element("text_input", [], {
|
|
640
|
+
val_from_variable_path: leading_variable_path,
|
|
641
|
+
...(variables_data_type_remaining?.attributes ?? {}),
|
|
642
|
+
})
|
|
643
|
+
}
|
|
644
|
+
return astc_element("base_text", [], {
|
|
645
|
+
content_from_variable_path: leading_variable_path,
|
|
646
|
+
size: 10,
|
|
647
|
+
...(variables_data_type_remaining?.attributes ?? {}),
|
|
648
|
+
})
|
|
649
|
+
} else if (["int_literal", "float_literal", "bigint_literal"].includes(variables_data_type_remaining?.type)) {
|
|
650
|
+
if (preferred_content_use == "input") {
|
|
651
|
+
return astc_element("text_input", [], {
|
|
652
|
+
type: "number",
|
|
653
|
+
val_from_variable_path: leading_variable_path,
|
|
654
|
+
...(variables_data_type_remaining?.attributes ?? {}),
|
|
655
|
+
})
|
|
656
|
+
}
|
|
657
|
+
return astc_element("number", [], {
|
|
658
|
+
val_from_variable_path: leading_variable_path,
|
|
659
|
+
...(variables_data_type_remaining?.attributes ?? {}),
|
|
660
|
+
})
|
|
661
|
+
} else if (variables_data_type_remaining?.type == "location_literal") {
|
|
662
|
+
if (preferred_content_use == "input") {
|
|
663
|
+
return astc_element("location_input", [], {
|
|
664
|
+
is_popover_button: true,
|
|
665
|
+
is_popover: true,
|
|
666
|
+
val_from_variable_path: leading_variable_path,
|
|
667
|
+
...(variables_data_type_remaining?.attributes ?? {}),
|
|
668
|
+
})
|
|
669
|
+
}
|
|
670
|
+
return astc_element("location", [], {
|
|
671
|
+
val_from_variable_path: leading_variable_path,
|
|
672
|
+
...(variables_data_type_remaining?.attributes ?? {}),
|
|
673
|
+
})
|
|
674
|
+
} else if (variables_data_type_remaining?.type == "time_zone_literal") {
|
|
675
|
+
if (preferred_content_use == "input") {
|
|
676
|
+
return astc_element("dropdown", [], {
|
|
677
|
+
options: time_zone_options,
|
|
678
|
+
is_button_compressed: true,
|
|
679
|
+
val_from_variable_path: leading_variable_path,
|
|
680
|
+
...(variables_data_type_remaining?.attributes ?? {}),
|
|
681
|
+
})
|
|
682
|
+
}
|
|
683
|
+
return astc_element("base_text", [], {
|
|
684
|
+
content_from_variable_path: leading_variable_path,
|
|
685
|
+
...(variables_data_type_remaining?.attributes ?? {}),
|
|
686
|
+
})
|
|
687
|
+
} else if (variables_data_type_remaining?.type == "language_literal") {
|
|
688
|
+
if (preferred_content_use == "input") {
|
|
689
|
+
return astc_element("dropdown", [], {
|
|
690
|
+
options: language_options,
|
|
691
|
+
is_compressed: true,
|
|
692
|
+
val_from_variable_path: leading_variable_path,
|
|
693
|
+
...(variables_data_type_remaining?.attributes ?? {}),
|
|
694
|
+
})
|
|
695
|
+
}
|
|
696
|
+
return astc_element("base_text", [], {
|
|
697
|
+
content_from_variable_path: leading_variable_path,
|
|
698
|
+
...(variables_data_type_remaining?.attributes ?? {}),
|
|
699
|
+
})
|
|
700
|
+
} else if (variables_data_type_remaining?.type == "json_literal") {
|
|
701
|
+
if (preferred_content_use == "input") {
|
|
702
|
+
return astc_element("json", [], {
|
|
703
|
+
val_from_variable_path: leading_variable_path,
|
|
704
|
+
...(variables_data_type_remaining?.attributes ?? {}),
|
|
705
|
+
is_edit_mode: true,
|
|
706
|
+
})
|
|
707
|
+
}
|
|
708
|
+
return astc_element("json", [], {
|
|
709
|
+
content_from_variable_path: leading_variable_path,
|
|
710
|
+
...(variables_data_type_remaining?.attributes ?? {}),
|
|
711
|
+
})
|
|
712
|
+
} else if (variables_data_type_remaining?.type == "boolean_literal") {
|
|
713
|
+
if (preferred_content_use == "input") {
|
|
714
|
+
return astc_element("checkbox", [], {
|
|
715
|
+
type: "toggle",
|
|
716
|
+
val_from_variable_path: leading_variable_path,
|
|
717
|
+
...(variables_data_type_remaining?.attributes ?? {}),
|
|
718
|
+
})
|
|
719
|
+
}
|
|
720
|
+
return astc_element("base_text", [], {
|
|
721
|
+
content_from_variable_path: leading_variable_path,
|
|
722
|
+
...(variables_data_type_remaining?.attributes ?? {}),
|
|
723
|
+
})
|
|
724
|
+
} else if (variables_data_type_remaining?.type == "email_address_literal") {
|
|
725
|
+
if (preferred_content_use == "input") {
|
|
726
|
+
return astc_element("text_input", [], {
|
|
727
|
+
type: "email",
|
|
728
|
+
val_from_variable_path: leading_variable_path,
|
|
729
|
+
...(variables_data_type_remaining?.attributes ?? {}),
|
|
730
|
+
})
|
|
731
|
+
}
|
|
732
|
+
return astc_element("email", [], {
|
|
733
|
+
val_from_variable_path: leading_variable_path,
|
|
734
|
+
})
|
|
735
|
+
} else if (variables_data_type_remaining?.type == "time_literal") {
|
|
736
|
+
if (preferred_content_use == "input") {
|
|
737
|
+
return astc_element("time_input", [], {
|
|
738
|
+
val_from_variable_path: leading_variable_path,
|
|
739
|
+
...(variables_data_type_remaining?.attributes ?? {}),
|
|
740
|
+
})
|
|
741
|
+
}
|
|
742
|
+
return astc_element("time", [], {
|
|
743
|
+
val_from_variable_path: leading_variable_path,
|
|
744
|
+
})
|
|
745
|
+
} else if (variables_data_type_remaining?.type == "epoch_literal") {
|
|
746
|
+
if (preferred_content_use == "input") {
|
|
747
|
+
return astc_element("time_input", [], {
|
|
748
|
+
format: "epoch",
|
|
749
|
+
val_from_variable_path: leading_variable_path,
|
|
750
|
+
...(variables_data_type_remaining?.attributes ?? {}),
|
|
751
|
+
})
|
|
752
|
+
}
|
|
753
|
+
return astc_element("time", [], {
|
|
754
|
+
format: "epoch",
|
|
755
|
+
val_from_variable_path: leading_variable_path,
|
|
756
|
+
...(variables_data_type_remaining?.attributes ?? {}),
|
|
757
|
+
})
|
|
758
|
+
} else if (variables_data_type_remaining?.type == "cron_literal") {
|
|
759
|
+
if (preferred_content_use == "input") {
|
|
760
|
+
return astc_element("cron_input", [], {
|
|
761
|
+
val_from_variable_path: leading_variable_path,
|
|
762
|
+
...(variables_data_type_remaining?.attributes ?? {}),
|
|
763
|
+
})
|
|
764
|
+
}
|
|
765
|
+
return astc_element("cron", [], {
|
|
766
|
+
val_from_variable_path: leading_variable_path,
|
|
767
|
+
})
|
|
768
|
+
} else if (variables_data_type_remaining?.type == "phone_literal") {
|
|
769
|
+
if (preferred_content_use == "input") {
|
|
770
|
+
return astc_element("phone_input", [], {
|
|
771
|
+
val_from_variable_path: leading_variable_path,
|
|
772
|
+
...(variables_data_type_remaining?.attributes ?? {}),
|
|
773
|
+
})
|
|
774
|
+
}
|
|
775
|
+
return astc_element("phone_number", [], {
|
|
776
|
+
val_from_variable_path: leading_variable_path,
|
|
777
|
+
...(variables_data_type_remaining?.attributes ?? {}),
|
|
778
|
+
})
|
|
779
|
+
} else if (variables_data_type_remaining?.type == "array_uniform_literal") {
|
|
780
|
+
if (preferred_content_use == "input") {
|
|
781
|
+
const child_astc = variables_data_type_remaining_to_astc(
|
|
782
|
+
variables_data_type_remaining?.items,
|
|
783
|
+
preferred_content_use,
|
|
784
|
+
[...leading_variable_path, ["loop_index"]]
|
|
785
|
+
)
|
|
786
|
+
return astc_element("array_uniform_input", [child_astc], {
|
|
787
|
+
val_from_variable_path: leading_variable_path,
|
|
788
|
+
...(variables_data_type_remaining?.attributes ?? {}),
|
|
789
|
+
iter_identifier: "loop_index",
|
|
790
|
+
})
|
|
791
|
+
}
|
|
792
|
+
// if (preferred_content_type == "object") {
|
|
793
|
+
// // maybe infer as table
|
|
794
|
+
// }
|
|
795
|
+
const child_astc = variables_data_type_remaining_to_astc(
|
|
796
|
+
variables_data_type_remaining?.items,
|
|
797
|
+
preferred_content_use,
|
|
798
|
+
[...leading_variable_path, ["loop_index"]]
|
|
799
|
+
)
|
|
800
|
+
return astc_element("loop", [child_astc], {
|
|
801
|
+
val_from_variable_path: leading_variable_path,
|
|
802
|
+
...(variables_data_type_remaining?.attributes ?? {}),
|
|
803
|
+
font_size: 1.2,
|
|
804
|
+
iter_identifier: "loop_index",
|
|
805
|
+
})
|
|
806
|
+
// } else if (variables_data_type_remaining?.type == "list") {
|
|
807
|
+
// list input tbd just content input i guess
|
|
808
|
+
// but im thinking loops are for same children repeated but lists can be different so basically a div with no div tag
|
|
809
|
+
// let children = []
|
|
810
|
+
// if (Array.isArray(variables_data_type_remaining?.items)) {
|
|
811
|
+
// for (let item of variables_data_type_remaining?.items) {
|
|
812
|
+
// children.push(variables_data_type_remaining_to_astc(item?.type, preferred_content_use, leading_variable_path))
|
|
813
|
+
// }
|
|
814
|
+
// }
|
|
815
|
+
// return astc_element("list", children)
|
|
816
|
+
} else if (variables_data_type_remaining?.type == "object_uniform_literal") {
|
|
817
|
+
if (preferred_content_use == "input") {
|
|
818
|
+
const child_astc = variables_data_type_remaining_to_astc(
|
|
819
|
+
variables_data_type_remaining?.items,
|
|
820
|
+
preferred_content_use
|
|
821
|
+
)
|
|
822
|
+
return astc_element("object_uniform_input", [child_astc], {
|
|
823
|
+
val_from_variable_path: leading_variable_path,
|
|
824
|
+
...(variables_data_type_remaining?.attributes ?? {}),
|
|
825
|
+
})
|
|
826
|
+
}
|
|
827
|
+
const child_astc = variables_data_type_remaining_to_astc(
|
|
828
|
+
variables_data_type_remaining?.items,
|
|
829
|
+
preferred_content_use
|
|
830
|
+
)
|
|
831
|
+
return astc_element("object_uniform", [child_astc], {
|
|
832
|
+
val_from_variable_path: leading_variable_path,
|
|
833
|
+
...(variables_data_type_remaining?.attributes ?? {}),
|
|
834
|
+
})
|
|
835
|
+
} else if (variables_data_type_remaining?.type == "object_literal") {
|
|
836
|
+
const label = variables_data_type_remaining?.attributes
|
|
837
|
+
? astc_element("base_text", [], {
|
|
838
|
+
content: variables_data_type_remaining?.attributes?.label,
|
|
839
|
+
...(variables_data_type_remaining?.attributes ?? {}),
|
|
840
|
+
font_size: 1.2,
|
|
841
|
+
})
|
|
842
|
+
: null
|
|
843
|
+
if (preferred_content_use == "input") {
|
|
844
|
+
let children = variables_data_type_remaining?.attributes?.label ? [label] : []
|
|
845
|
+
for (let [key, val] of Object.entries(variables_data_type_remaining?.properties || {})) {
|
|
846
|
+
let property_children = []
|
|
847
|
+
property_children.push(
|
|
848
|
+
astc_element("base_text", [], {
|
|
849
|
+
content: `${key ?? "NULL"}:`,
|
|
850
|
+
...(variables_data_type_remaining?.attributes ?? {}),
|
|
851
|
+
font_size: 1.2,
|
|
852
|
+
})
|
|
853
|
+
)
|
|
854
|
+
if (val?.type != null) {
|
|
855
|
+
const property_astc = variables_data_type_remaining_to_astc(val, preferred_content_use, [
|
|
856
|
+
...(Array.isArray(leading_variable_path) ? leading_variable_path : []),
|
|
857
|
+
key,
|
|
858
|
+
])
|
|
859
|
+
property_children.push(property_astc)
|
|
860
|
+
} else {
|
|
861
|
+
property_children.push(astc_element("em", [], { content: "Data Type Not Set", font_size: 1.2 }))
|
|
862
|
+
}
|
|
863
|
+
children.push(astc_element("div", property_children))
|
|
864
|
+
}
|
|
865
|
+
return astc_element("div", children, { ...(variables_data_type_remaining?.attributes ?? {}) })
|
|
866
|
+
}
|
|
867
|
+
let children = label ? [label] : []
|
|
868
|
+
for (let [key, val] of Object.entries(variables_data_type_remaining?.properties || {})) {
|
|
869
|
+
let property_children = []
|
|
870
|
+
property_children.push(
|
|
871
|
+
astc_element("base_text", [], {
|
|
872
|
+
content: `${key ?? "NULL"}:`,
|
|
873
|
+
...(variables_data_type_remaining?.attributes ?? {}),
|
|
874
|
+
font_size: 1.2,
|
|
875
|
+
})
|
|
876
|
+
)
|
|
877
|
+
if (val?.type != null) {
|
|
878
|
+
const property_astc = variables_data_type_remaining_to_astc(val, preferred_content_use, [
|
|
879
|
+
...(Array.isArray(leading_variable_path) ? leading_variable_path : []),
|
|
880
|
+
key,
|
|
881
|
+
])
|
|
882
|
+
property_children.push(property_astc)
|
|
883
|
+
} else {
|
|
884
|
+
property_children.push(astc_element("em", [], { content: "Data Type Not Set", font_size: 1.2 }))
|
|
885
|
+
}
|
|
886
|
+
children.push(astc_element("div", property_children))
|
|
887
|
+
}
|
|
888
|
+
return astc_element("div", children, { ...(variables_data_type_remaining?.attributes ?? {}) })
|
|
889
|
+
} else if (variables_data_type_remaining?.type == "table_id_for_foreign_row_literal") {
|
|
890
|
+
if (preferred_content_use == "input") {
|
|
891
|
+
return astc_element("table_row_id_input", [], {
|
|
892
|
+
table_id: variables_data_type_remaining?.attributes?.table_id,
|
|
893
|
+
val_from_variable_path: leading_variable_path,
|
|
894
|
+
...(variables_data_type_remaining?.attributes ?? {}),
|
|
895
|
+
})
|
|
896
|
+
}
|
|
897
|
+
return astc_element("base_text", [], {
|
|
898
|
+
content_from_variable_path: leading_variable_path,
|
|
899
|
+
size: 10,
|
|
900
|
+
...(variables_data_type_remaining?.attributes ?? {}),
|
|
901
|
+
})
|
|
902
|
+
}
|
|
903
|
+
|
|
904
|
+
// let preferred_content_type = (
|
|
905
|
+
// preferred_content_use == "display"
|
|
906
|
+
// ? node_types?.[variables_data_type_remaining?.type]?.display_options
|
|
907
|
+
// : node_types?.[variables_data_type_remaining?.type]?.input_options
|
|
908
|
+
// )?.[0]
|
|
909
|
+
// if (preferred_content_type) {
|
|
910
|
+
// // let attributes = {}
|
|
911
|
+
// // if (Object.keys(node_types?.[preferred_content_type]?.attributes || {}).length > 0) {
|
|
912
|
+
// // for (let [key, value] of Object.entries(node_types?.[preferred_content_type]?.attributes || {})) {
|
|
913
|
+
// // if (["val_from_variable_path", "val"].includes(key)) {
|
|
914
|
+
// // attributes["val_from_variable_path"] = leading_variable_path
|
|
915
|
+
// // } else if (["content_from_variable_path", "content"].includes(key)) {
|
|
916
|
+
// // attributes["content_from_variable_path"] = leading_variable_path
|
|
917
|
+
// // } else {
|
|
918
|
+
// // attributes[key] = value?.default_value ?? null
|
|
919
|
+
// // }
|
|
920
|
+
// // }
|
|
921
|
+
// // }
|
|
922
|
+
// // astc_loc.attributes = attributes
|
|
923
|
+
// return astc_element(preferred_content_type, [], attributes)
|
|
924
|
+
// }
|
|
925
|
+
return null
|
|
926
|
+
}
|
|
927
|
+
|
|
928
|
+
export function json_to_data_type(data, type = null, is_list_child = false) {
|
|
929
|
+
let structure = {
|
|
930
|
+
type: null,
|
|
931
|
+
attributes: {},
|
|
932
|
+
}
|
|
933
|
+
if (type == "number" || (!type && typeof data === "number")) {
|
|
934
|
+
if (data > 1000000000 && data < 2500000000) {
|
|
935
|
+
structure = {
|
|
936
|
+
...structure,
|
|
937
|
+
type: "epoch_literal",
|
|
938
|
+
attributes: {
|
|
939
|
+
min: null,
|
|
940
|
+
max: null,
|
|
941
|
+
},
|
|
942
|
+
}
|
|
943
|
+
} else {
|
|
944
|
+
structure = {
|
|
945
|
+
...structure,
|
|
946
|
+
type: "float_literal",
|
|
947
|
+
attributes: {
|
|
948
|
+
min: null,
|
|
949
|
+
max: null,
|
|
950
|
+
},
|
|
951
|
+
}
|
|
952
|
+
}
|
|
953
|
+
} else if (type == "slider") {
|
|
954
|
+
structure = {
|
|
955
|
+
...structure,
|
|
956
|
+
type: "slider_literal",
|
|
957
|
+
attributes: {
|
|
958
|
+
min: null,
|
|
959
|
+
max: null,
|
|
960
|
+
step: null,
|
|
961
|
+
},
|
|
962
|
+
}
|
|
963
|
+
} else if (type == "boolean" || (!type && typeof data === "boolean")) {
|
|
964
|
+
structure = {
|
|
965
|
+
...structure,
|
|
966
|
+
type: "boolean_literal",
|
|
967
|
+
attributes: {
|
|
968
|
+
on_val: null,
|
|
969
|
+
off_val: null,
|
|
970
|
+
},
|
|
971
|
+
}
|
|
972
|
+
} else if (type == "text" || (!type && typeof data === "string")) {
|
|
973
|
+
structure = {
|
|
974
|
+
...structure,
|
|
975
|
+
type: "text_literal",
|
|
976
|
+
}
|
|
977
|
+
} else if (type == "time") {
|
|
978
|
+
structure = {
|
|
979
|
+
...structure,
|
|
980
|
+
type: "time_literal",
|
|
981
|
+
}
|
|
982
|
+
} else if (type == "email") {
|
|
983
|
+
structure = {
|
|
984
|
+
...structure,
|
|
985
|
+
type: "email_literal",
|
|
986
|
+
}
|
|
987
|
+
} else if (type == "phone_literal") {
|
|
988
|
+
structure = {
|
|
989
|
+
...structure,
|
|
990
|
+
type: "phone_literal",
|
|
991
|
+
}
|
|
992
|
+
} else if (type == "cron_literal") {
|
|
993
|
+
structure = {
|
|
994
|
+
...structure,
|
|
995
|
+
type: "cron_literal",
|
|
996
|
+
}
|
|
997
|
+
} else if (type == "dropdown") {
|
|
998
|
+
structure = {
|
|
999
|
+
...structure,
|
|
1000
|
+
type: "dropdown_literal",
|
|
1001
|
+
attributes: {
|
|
1002
|
+
options: [],
|
|
1003
|
+
},
|
|
1004
|
+
}
|
|
1005
|
+
} else if (type == "color_literal") {
|
|
1006
|
+
structure = {
|
|
1007
|
+
...structure,
|
|
1008
|
+
type: "color_literal",
|
|
1009
|
+
}
|
|
1010
|
+
} else if (type == "image") {
|
|
1011
|
+
structure = {
|
|
1012
|
+
...structure,
|
|
1013
|
+
type: "image_literal",
|
|
1014
|
+
}
|
|
1015
|
+
} else if (type == "audio") {
|
|
1016
|
+
structure = {
|
|
1017
|
+
...structure,
|
|
1018
|
+
type: "audio_literal",
|
|
1019
|
+
}
|
|
1020
|
+
} else if (type == "location") {
|
|
1021
|
+
structure = {
|
|
1022
|
+
...structure,
|
|
1023
|
+
type: "location_literal",
|
|
1024
|
+
}
|
|
1025
|
+
} else if (type == "id") {
|
|
1026
|
+
structure = {
|
|
1027
|
+
...structure,
|
|
1028
|
+
type: "id_literal",
|
|
1029
|
+
attributes: {
|
|
1030
|
+
type: "lowercase_chars",
|
|
1031
|
+
random_char_length: 20,
|
|
1032
|
+
},
|
|
1033
|
+
}
|
|
1034
|
+
} else if (type == "loop" || (!type && Array.isArray(data))) {
|
|
1035
|
+
let fattened_data_sample = data?.[0] // try and iterate over all the rows in case the first one has some null vals that later rows have good sample of
|
|
1036
|
+
if (Array.isArray(data)) {
|
|
1037
|
+
for (let i = 0; i < data.length; i++) {
|
|
1038
|
+
if (typeof data?.[i] == "object" && !Array.isArray(data?.[i])) {
|
|
1039
|
+
for (let [key, val] of Object.entries(data?.[i])) {
|
|
1040
|
+
if (fattened_data_sample?.[key] == null) {
|
|
1041
|
+
fattened_data_sample[key] = val
|
|
1042
|
+
}
|
|
1043
|
+
}
|
|
1044
|
+
}
|
|
1045
|
+
}
|
|
1046
|
+
}
|
|
1047
|
+
structure = {
|
|
1048
|
+
...structure,
|
|
1049
|
+
type: "loop",
|
|
1050
|
+
items: json_to_data_type(fattened_data_sample, null, true),
|
|
1051
|
+
attributes: {},
|
|
1052
|
+
}
|
|
1053
|
+
} else if (type == "list" || (!type && Array.isArray(data))) {
|
|
1054
|
+
// tbd loop vs list
|
|
1055
|
+
structure = {
|
|
1056
|
+
...structure,
|
|
1057
|
+
type: "list_literal",
|
|
1058
|
+
items: json_to_data_type(data?.[0], null, true),
|
|
1059
|
+
attributes: {},
|
|
1060
|
+
}
|
|
1061
|
+
} else if (type == "object" || (!type && typeof data === "object" && !Array.isArray(data) && data !== null)) {
|
|
1062
|
+
// prob match on expected atttributes to give better match like c l h is_dark_theme might bet color_literal not object
|
|
1063
|
+
// let node_type_best_match = null
|
|
1064
|
+
// let node_type_best_match_attr_count = 1
|
|
1065
|
+
// for (let [node_type_key, node_type_val] of Object.entries(node_types || {})) {
|
|
1066
|
+
// if (Object.keys(node_type_val?.attributes || {}).length > 0) {
|
|
1067
|
+
// let keys_that_are_an_attribute_match = 0
|
|
1068
|
+
// for (let property_key of Object.keys(data || {})) {
|
|
1069
|
+
// if (Object.keys(node_type_val?.attributes || {}).includes(property_key)) {
|
|
1070
|
+
// keys_that_are_an_attribute_match++
|
|
1071
|
+
// }
|
|
1072
|
+
// }
|
|
1073
|
+
// if (keys_that_are_an_attribute_match > node_type_best_match_attr_count) {
|
|
1074
|
+
// console.log("good", { keys_that_are_an_attribute_match, node_type_key, node_type_val })
|
|
1075
|
+
// node_type_best_match = node_type_key
|
|
1076
|
+
// node_type_best_match_attr_count = keys_that_are_an_attribute_match
|
|
1077
|
+
// }
|
|
1078
|
+
// }
|
|
1079
|
+
// // console.log("node_type_best_match", node_type_best_match)
|
|
1080
|
+
// }
|
|
1081
|
+
|
|
1082
|
+
// if (node_type_best_match) {
|
|
1083
|
+
// structure = json_to_data_type(data, node_type_best_match)
|
|
1084
|
+
// console.log("str", { node_type_best_match, structure })
|
|
1085
|
+
let keys = Object.keys(data || {})
|
|
1086
|
+
if (keys.includes("l") && keys.includes("c") && keys.includes("h")) {
|
|
1087
|
+
structure = json_to_data_type(data, "color_literal")
|
|
1088
|
+
} else if (keys.includes("epoch") && keys.includes("hour") && keys.includes("year")) {
|
|
1089
|
+
structure = json_to_data_type(data, "time_literal")
|
|
1090
|
+
} else if (keys.includes("cron")) {
|
|
1091
|
+
structure = json_to_data_type(data, "cron_literal")
|
|
1092
|
+
} else if (keys.includes("main_number") && keys.includes("country_code")) {
|
|
1093
|
+
structure = json_to_data_type(data, "phone_literal")
|
|
1094
|
+
} else {
|
|
1095
|
+
let properties = {}
|
|
1096
|
+
for (let key of Object.keys(data || {})) {
|
|
1097
|
+
const guessed_structure = json_to_data_type(data[key])
|
|
1098
|
+
properties[key] = {
|
|
1099
|
+
...guessed_structure,
|
|
1100
|
+
attributes: {
|
|
1101
|
+
...guessed_structure.attributes,
|
|
1102
|
+
...(is_list_child
|
|
1103
|
+
? {
|
|
1104
|
+
is_sortable: true,
|
|
1105
|
+
is_searchable: true,
|
|
1106
|
+
column_min_width: 5,
|
|
1107
|
+
column_max_width: 10,
|
|
1108
|
+
display_order: null,
|
|
1109
|
+
is_shown: true,
|
|
1110
|
+
filter_in_min: null,
|
|
1111
|
+
filter_in_max: null,
|
|
1112
|
+
}
|
|
1113
|
+
: {}),
|
|
1114
|
+
},
|
|
1115
|
+
}
|
|
1116
|
+
}
|
|
1117
|
+
structure = {
|
|
1118
|
+
...structure,
|
|
1119
|
+
type: "object_literal",
|
|
1120
|
+
properties: properties,
|
|
1121
|
+
attributes: {
|
|
1122
|
+
search_val: null,
|
|
1123
|
+
},
|
|
1124
|
+
}
|
|
1125
|
+
}
|
|
1126
|
+
}
|
|
1127
|
+
return structure
|
|
1128
|
+
}
|