@chocbite/ts-lib-ui 1.0.4 → 1.0.6
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/AGENTS.md +609 -0
- package/SOURCE.md +17135 -0
- package/base/index.d.mts +1 -1
- package/base/index.mjs +1 -1
- package/base/index.mjs.map +1 -1
- package/canvas/index.d.mts +1 -1
- package/canvas/index.mjs +35 -19
- package/canvas/index.mjs.map +1 -1
- package/context-menu/index.d.mts +1 -1
- package/context-menu/index.mjs +1 -1
- package/{context-menu-Cz9rqUaM.mjs → context-menu-Bo8R6DmK.mjs} +2 -2
- package/{context-menu-Cz9rqUaM.mjs.map → context-menu-Bo8R6DmK.mjs.map} +1 -1
- package/form/index.d.mts +3 -3
- package/form/index.mjs +2 -2
- package/icons/index.d.mts +1 -1
- package/{index-DCn7acFY.d.mts → index-BTUFkF9s.d.mts} +4 -4
- package/{index-BDWg5GX2.d.mts → index-ClIBfrHy.d.mts} +2 -2
- package/{index-CvzH3M_5.d.mts → index-ClfL2SQR.d.mts} +2 -2
- package/{index-DhRb2iA8.d.mts → index-Pr2sLv9e.d.mts} +2 -2
- package/keyboard/index.d.mts +1 -1
- package/keyboard/index.mjs +1 -1
- package/list/index.d.mts +1 -1
- package/list/index.mjs +1 -1
- package/{list-DXkEJKjx.mjs → list-DOXIQOEY.mjs} +4 -4
- package/list-DOXIQOEY.mjs.map +1 -0
- package/package.json +7 -2
- package/spinner/index.d.mts +1 -1
- package/spinner/index.mjs +1 -1
- package/state_ui/index.mjs +2 -0
- package/{state-OCzEmq3j.mjs → state_ui-Bm3TeKNL.mjs} +3 -3
- package/state_ui-Bm3TeKNL.mjs.map +1 -0
- package/svg/index.d.mts +1 -1
- package/test/index.d.mts +98 -0
- package/test/index.mjs +193 -0
- package/test/index.mjs.map +1 -0
- package/theme/index.d.mts +1 -1
- package/theme/index.mjs +1 -1
- package/{theme-CFeGnUuF.mjs → theme-DgVtLDzP.mjs} +2 -2
- package/{theme-CFeGnUuF.mjs.map → theme-DgVtLDzP.mjs.map} +1 -1
- package/list-DXkEJKjx.mjs.map +0 -1
- package/state/index.mjs +0 -2
- package/state-OCzEmq3j.mjs.map +0 -1
- /package/{state → state_ui}/index.d.mts +0 -0
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"context-menu-Cz9rqUaM.mjs","names":[],"sources":["../src/context-menu/shared.ts","../src/context-menu/line.ts","../src/context-menu/devider.ts","../src/context-menu/container.ts","../src/context-menu/engine.ts","../src/context-menu/buffer.ts","../src/context-menu/option.ts","../src/context-menu/submenu.ts","../src/context-menu/menu.ts","../src/context-menu/index.ts"],"sourcesContent":["import { BLUE, GREY } from \"@chocbite/ts-lib/colors\";\nimport { theme_init_variable_root } from \"#theme\";\n\nconst variables = theme_init_variable_root(\n \"contextmenu\",\n \"Context Menu\",\n \"Right click or touch and hold context menu appearance\",\n);\nvariables.make_variable(\n \"background\",\n \"Background Color\",\n \"Color of background\",\n GREY[\"50\"],\n GREY[\"900\"],\n \"Color\",\n undefined,\n);\nvariables.make_variable(\n \"text\",\n \"Text Color\",\n \"Color of text\",\n GREY[\"600\"],\n GREY[\"400\"],\n \"Color\",\n undefined,\n);\nvariables.make_variable(\n \"hover\",\n \"Hover Color\",\n \"Background color of line when hovering over it\",\n BLUE[\"200\"],\n BLUE[\"900\"],\n \"Color\",\n undefined,\n);\nvariables.make_variable(\n \"hoverText\",\n \"Text Color\",\n \"Standard text color\",\n GREY[\"900\"],\n GREY[\"50\"],\n \"Color\",\n undefined,\n);\nvariables.make_variable(\n \"border\",\n \"Border Color\",\n \"Color of border and deviders\",\n GREY[\"300\"],\n GREY[\"800\"],\n \"Color\",\n undefined,\n);\n","import { Base } from \"#base\";\nimport \"./option.scss\";\nimport \"./shared\";\n\nexport interface ContextMenuLine {}\n\nexport abstract class MenuLine extends Base implements ContextMenuLine {\n /**Returns the name used to define the element */\n static element_name() {\n return \"@abstract@\";\n }\n /**Returns the namespace override for the element*/\n static element_name_space() {\n return \"contextmenu\";\n }\n\n abstract do_focus(dir?: boolean): void;\n\n /**True for lines that can not take focus, like dividers, focus moves past them*/\n get skips_focus() {\n return false;\n }\n\n /**Changes focus to the next line, wrapping around and skipping lines that can not take focus\n * @param direction false is next sibling, true is previous */\n focus_next(direction?: boolean) {\n const parent = this.parentElement;\n if (!parent) return;\n let line = direction\n ? this.previousElementSibling\n : this.nextElementSibling;\n for (;;) {\n line ??= direction ? parent.lastElementChild : parent.firstElementChild;\n //Back at the start, there is no other line to focus\n if (!line || line === this) return;\n if (!(line as MenuLine).skips_focus)\n return (line as MenuLine).do_focus(direction);\n line = direction ? line.previousElementSibling : line.nextElementSibling;\n }\n }\n}\n","import { define_element } from \"#base\";\nimport \"./devider.scss\";\nimport { ContextMenuLine, MenuLine } from \"./line\";\n\nexport interface ContextMenuDevider extends ContextMenuLine {}\n\nexport class Devider extends MenuLine implements ContextMenuDevider {\n /**Returns the name used to define the element */\n static element_name() {\n return \"devider\";\n }\n\n get skips_focus() {\n return true;\n }\n\n do_focus(dir?: boolean) {\n this.focus_next(dir);\n }\n}\ndefine_element(Devider);\n\nexport function context_devider(): ContextMenuDevider {\n return new Devider();\n}\n","import { Base, define_element } from \"#base\";\nimport \"./container.scss\";\nimport { ContextMenu } from \"./menu\";\n\nexport class Container extends Base {\n #active_element_buffer: HTMLOrSVGElement | null | undefined;\n #replacing = false;\n\n /**Returns the name used to define the element */\n static element_name() {\n return \"container\";\n }\n /**Returns the namespace override for the element*/\n static element_name_space() {\n return \"contextmenu\";\n }\n\n constructor() {\n super();\n this.tabIndex = -1;\n const preventer = (e: Event) => {\n e.preventDefault();\n e.stopPropagation();\n };\n this.oncontextmenu = preventer;\n this.onpointerdown = preventer;\n this.onpointerup = preventer;\n this.onpointercancel = preventer;\n this.onpointerenter = preventer;\n this.onpointerleave = preventer;\n this.onpointermove = preventer;\n this.onpointerout = preventer;\n this.onpointerout = preventer;\n this.onclick = preventer;\n }\n\n /**Attaches a menu to the container */\n attach_menu(menu: ContextMenu) {\n menu.container = this;\n const old = this.firstElementChild as ContextMenu | null;\n if (old) {\n //Closed before replacing, the browser closes it from a focusout while it is being removed otherwise,\n //focus still returns to the element from before the old menu\n this.#replacing = true;\n old.close_down();\n old.close_up();\n this.#replacing = false;\n } else\n this.#active_element_buffer = this.ownerDocument\n .activeElement as HTMLOrSVGElement | null;\n this.replaceChildren(menu);\n return menu;\n }\n\n /**Closes open context menu */\n close_up() {\n if (this.#replacing) return;\n if (this.#active_element_buffer) {\n this.#active_element_buffer.focus();\n if (\n (this.ownerDocument.activeElement as any) !==\n this.#active_element_buffer\n ) {\n this.focus();\n }\n this.#active_element_buffer = undefined;\n } else {\n this.focus();\n }\n }\n}\ndefine_element(Container);\n","import { DOCUMENT_HANDLER } from \"#document\";\nimport type { Option } from \"@chocbite/ts-lib/result\";\nimport { Container } from \"./container\";\nimport \"./engine.scss\";\nimport { ContextMenu } from \"./menu\";\n\nexport const CONTEXT_MENY_SYMBOL = Symbol(\"context_menu\");\n\ndeclare global {\n interface Document {\n [CONTEXT_MENY_SYMBOL]: Container | undefined;\n }\n interface Element {\n [CONTEXT_MENY_SYMBOL]: EventListenerOrEventListenerObject | undefined;\n }\n}\n\n/**Default context menu, false blocks the operating system context menu, undefined leaves it*/\nlet default_menu: ContextMenu | (() => Option<ContextMenu>) | false | undefined;\n\n/**Blocks the operating system context menu when the default is false*/\nconst block_os_menu = (e: Event) => e.preventDefault();\n\nDOCUMENT_HANDLER.events.on(\"added\", (e) => {\n apply_to_doc(e.data);\n});\nDOCUMENT_HANDLER.for_documents((doc) => {\n apply_to_doc(doc);\n});\n\nfunction apply_to_doc(doc: Document) {\n const container = new Container();\n doc[CONTEXT_MENY_SYMBOL] = container;\n doc.documentElement.appendChild(container);\n apply_default_to_doc(doc);\n}\n\n/**Applies the current default context menu to a document*/\nfunction apply_default_to_doc(doc: Document) {\n const root = doc.documentElement;\n context_menu_detach(root);\n root.removeEventListener(\"contextmenu\", block_os_menu);\n if (default_menu) context_menu_attach(root, default_menu);\n else if (default_menu === false)\n root.addEventListener(\"contextmenu\", block_os_menu);\n}\n\n/**Attaches a context menu to the given element\n * @param element the element to attach the context menu to\n * @param lines the context menu to attach, if a function is given it will be called when the context menu is summoned\n * @param block a function that returns true if the context menu should not be summoned, if undefined the context menu will always be summoned*/\nexport function context_menu_attach(\n element: Element,\n lines: ContextMenu | (() => Option<ContextMenu>),\n block?: () => boolean,\n) {\n if (element[CONTEXT_MENY_SYMBOL]) context_menu_detach(element);\n const listener = (e: Event) => {\n e.preventDefault();\n e.stopPropagation();\n if (block && block()) return;\n const lineses =\n typeof lines === \"function\" ? lines().unwrap_or(undefined) : lines;\n if (!lineses) return;\n context_menu_summon(\n lineses,\n element,\n (e as MouseEvent).clientX,\n (e as MouseEvent).clientY,\n );\n };\n element.addEventListener(\"contextmenu\", listener);\n element[CONTEXT_MENY_SYMBOL] = listener;\n}\n\n/**Dettaches the context menu from the given element */\nexport function context_menu_detach(element: Element) {\n if (element[CONTEXT_MENY_SYMBOL]) {\n element.removeEventListener(\"contextmenu\", element[CONTEXT_MENY_SYMBOL]);\n delete element[CONTEXT_MENY_SYMBOL];\n }\n}\n\n/**Summons a context menu at a given location\n * @param menu the context menu to summon\n * @param element the element the context menu is referenced to, if undefined the context menu will appear in the main document\n * @param x x position for context menu, if undefined, will use element middle, if element undefined, will put context menu in the top left corner of the screen\n * @param y y position for context menu, if undefined, will use element middle, if element undefined, will put context menu in the top left corner of the screen\n * @param dont_cover when set true */\nexport function context_menu_summon(\n menu: ContextMenu,\n element?: Element,\n x?: number,\n y?: number,\n dont_cover?: boolean,\n) {\n const container = element\n ? element.ownerDocument[CONTEXT_MENY_SYMBOL]\n : DOCUMENT_HANDLER.main[CONTEXT_MENY_SYMBOL];\n if (container) {\n if (typeof x !== \"number\" || typeof y !== \"number\") {\n if (element) {\n const box = element.getBoundingClientRect();\n x = box.left + box.width / 2;\n y = box.top + box.height / 2;\n } else {\n x = 0;\n y = 0;\n }\n }\n container\n .attach_menu(menu)\n .set_position(x, y, dont_cover ? element : undefined);\n } else console.error(\"No context menu container available\");\n}\n\n/**Sets the default context menu for the page, the one used if no other context menu has been attached to the element\n * If set to false the operating system context menu is disabled and nothing will appear\n * If set undefined the operating systems context menu will be used*/\nexport function context_menu_default(\n lines: ContextMenu | (() => Option<ContextMenu>) | false | undefined,\n) {\n default_menu = lines;\n DOCUMENT_HANDLER.for_documents(apply_default_to_doc);\n}\n","import { define_element } from \"#base\";\nimport { Spinner } from \"#spinner\";\nimport \"./buffer.scss\";\nimport { MenuLine } from \"./line\";\n\nexport class Buffer extends MenuLine {\n /**Returns the name used to define the element */\n static element_name() {\n return \"buffer\";\n }\n\n constructor() {\n super();\n this.appendChild(new Spinner());\n }\n\n get skips_focus() {\n return true;\n }\n\n do_focus(dir: boolean) {\n this.focus_next(dir);\n }\n}\ndefine_element(Buffer);\n","import { define_element } from \"#base\";\nimport { ContextMenuLine, MenuLine } from \"./line\";\nimport { ContextMenu } from \"./menu\";\nimport \"./option.scss\";\n\nexport interface ContextMenuOption extends ContextMenuLine {}\n\nexport class MenuOption extends MenuLine implements ContextMenuOption {\n readonly func: () => void;\n\n /**Returns the name used to define the element */\n static element_name() {\n return \"option\";\n }\n\n constructor(\n text: string,\n func: () => void,\n icon?: SVGSVGElement,\n shortcut?: string,\n checkmark?: boolean,\n ) {\n super();\n this.func = func;\n this.tabIndex = 0;\n const icon_box = this.appendChild(document.createElement(\"div\"));\n icon_box.className = \"icon\";\n if (icon) icon_box.appendChild(icon);\n const text_box = this.appendChild(document.createElement(\"div\"));\n text_box.textContent = text;\n text_box.className = \"text\";\n const shortcut_box = this.appendChild(document.createElement(\"div\"));\n if (shortcut) shortcut_box.textContent = shortcut;\n shortcut_box.className = \"shortcut\";\n const check_mark_box = this.appendChild(document.createElement(\"div\"));\n if (checkmark) check_mark_box.textContent = \"✓\";\n check_mark_box.className = \"checkmark\";\n\n this.onclick = (e) => {\n e.stopPropagation();\n this.func();\n navigator.vibrate?.(25);\n (this.parentElement as ContextMenu).close_up();\n };\n\n this.onkeydown = (e) => {\n switch (e.code) {\n case \"Tab\":\n case \"ArrowUp\":\n case \"ArrowDown\":\n this.focus_next(e.shiftKey || e.code === \"ArrowUp\");\n break;\n case \"Enter\":\n case \"Space\":\n this.func();\n (this.parentElement as ContextMenu).close_up();\n break;\n case \"ArrowLeft\":\n case \"Escape\":\n return;\n }\n e.preventDefault();\n e.stopPropagation();\n };\n }\n\n do_focus(): void {\n this.focus();\n }\n}\ndefine_element(MenuOption);\n\nexport function context_line(\n text: string,\n func: () => void,\n icon?: SVGSVGElement,\n shortcut?: string,\n checkmark?: boolean,\n): ContextMenuOption {\n return new MenuOption(text, func, icon, shortcut, checkmark);\n}\n","import { define_element } from \"#base\";\nimport { material_chevron_right_rounded } from \"#icons\";\nimport { ContextMenuLine, MenuLine } from \"./line\";\nimport { ContextMenu } from \"./menu\";\nimport \"./submenu.scss\";\n\nexport interface ContextMenuSub extends ContextMenuLine {}\n\ntype Mutable<T> = {\n -readonly [P in keyof T]: T[P];\n};\nexport class MenuSub extends MenuLine implements ContextMenuSub {\n #menu: ContextMenu;\n #is_open?: boolean;\n #hover_time?: number;\n #block_time?: number;\n\n /**Returns the name used to define the element */\n static element_name() {\n return \"submenu\";\n }\n\n constructor(text: string, menu: ContextMenu, icon?: SVGSVGElement) {\n super();\n this.#menu = menu;\n this.tabIndex = 0;\n const icon_box = this.appendChild(document.createElement(\"div\"));\n icon_box.className = \"icon\";\n if (icon) icon_box.appendChild(icon);\n const text_box = this.appendChild(document.createElement(\"div\"));\n text_box.textContent = text;\n text_box.className = \"text\";\n const shortcut_box = this.appendChild(document.createElement(\"div\"));\n shortcut_box.className = \"shortcut\";\n const chevron_box = this.appendChild(document.createElement(\"div\"));\n chevron_box.appendChild(material_chevron_right_rounded());\n chevron_box.className = \"chevron\";\n\n this.onclick = (e) => {\n e.stopPropagation();\n if (!this.#block_time) {\n navigator.vibrate?.(25);\n if (this.#is_open) {\n this.close_down();\n } else {\n this.open();\n }\n }\n };\n\n this.onpointerenter = (e) => {\n if (e.pointerType !== \"touch\" && !this.#is_open) {\n this.#hover_time = window.setTimeout(() => {\n this.open();\n this.#block_time = window.setTimeout(() => {\n this.#block_time = 0;\n }, 500);\n }, 300);\n }\n };\n this.onpointerleave = () => {\n clearTimeout(this.#hover_time);\n };\n this.onkeydown = (e) => {\n switch (e.code) {\n case \"Tab\":\n case \"ArrowUp\":\n case \"ArrowDown\":\n this.focus_next(e.shiftKey || e.code === \"ArrowUp\");\n break;\n case \"ArrowRight\":\n case \"Enter\":\n case \"Space\":\n this.open();\n this.#menu.focus_next(false);\n break;\n case \"ArrowLeft\":\n case \"Escape\":\n return;\n }\n e.preventDefault();\n e.stopPropagation();\n };\n }\n\n /**Opens the sub menu */\n open() {\n const sub = this.parentElement as Mutable<ContextMenu>;\n if (sub) sub.close_down();\n (this.parentElement as Mutable<ContextMenu>).submenu = this;\n this.appendChild(this.#menu);\n this.#menu.set_position(0, 0, this);\n this.#is_open = true;\n }\n\n do_focus(): void {\n this.focus();\n }\n\n /**Closes menu by calling parent*/\n close() {\n this.focus();\n (this.parentElement as Mutable<ContextMenu>).submenu = undefined;\n this.removeChild(this.#menu);\n this.#is_open = false;\n }\n\n /**Closes the context menu down the tree*/\n close_down() {\n this.#menu.close_down();\n this.close();\n }\n\n /**Closes the context menu up the tree to the root*/\n close_up() {\n this.close();\n (this.parentElement as ContextMenu).close_up();\n }\n}\ndefine_element(MenuSub);\n\nexport function context_sub(\n text: string,\n menu: ContextMenu,\n icon?: SVGSVGElement,\n): ContextMenuSub {\n return new MenuSub(text, menu, icon);\n}\n","import { Base, define_element } from \"#base\";\nimport { material_close_rounded } from \"#icons\";\nimport { Buffer } from \"./buffer\";\nimport { Container } from \"./container\";\nimport { ContextMenuLine, MenuLine } from \"./line\";\nimport \"./menu.scss\";\nimport { MenuOption } from \"./option\";\nimport \"./shared\";\nimport { MenuSub } from \"./submenu\";\n\nexport type ContextMenuLines = ContextMenuLine[];\n\nexport class ContextMenu extends Base {\n /**Returns the name used to define the element */\n static element_name() {\n return \"menu\";\n }\n /**Returns the namespace override for the element*/\n static element_name_space() {\n return \"contextmenu\";\n }\n\n container: Container | undefined;\n readonly submenu: MenuSub | undefined;\n #closer: MenuOption | undefined;\n #x: number | undefined;\n #y: number | undefined;\n #element: Element | undefined;\n /**Spinner shown while promised lines load, cleared when the menu closes*/\n #loading: Buffer | undefined;\n #focus_out_handler = (e: FocusEvent) => {\n e.preventDefault();\n e.stopPropagation();\n if (!e.relatedTarget || !this.contains(e.relatedTarget as Node)) {\n this.close_up();\n this.close_down();\n }\n };\n #window_resize_handler = () => {\n this.set_position(this.#x, this.#y, this.#element);\n };\n\n #lines:\n | (\n | (ContextMenuLine | undefined)[]\n | Promise<(ContextMenuLine | undefined)[]>\n )\n | (() =>\n | (ContextMenuLine | undefined)[]\n | Promise<(ContextMenuLine | undefined)[]>);\n\n constructor(\n lines:\n | (\n | (ContextMenuLine | undefined)[]\n | Promise<(ContextMenuLine | undefined)[]>\n )\n | (() =>\n | (ContextMenuLine | undefined)[]\n | Promise<(ContextMenuLine | undefined)[]>),\n ) {\n super();\n this.#lines = lines;\n this.tabIndex = 0;\n this.onscroll = () => {\n this.close_down();\n };\n this.onkeydown = (e) => {\n if (e.code === \"Tab\" || e.code === \"ArrowUp\" || e.code === \"ArrowDown\")\n this.focus_next(e.shiftKey || e.code === \"ArrowUp\");\n else if (e.code === \"ArrowLeft\") {\n const parent = this.parentElement as MenuSub | Container;\n if (!(parent instanceof Container)) {\n parent.focus();\n parent.close_down();\n }\n } else if (e.code === \"Escape\") this.close_up();\n e.preventDefault();\n e.stopPropagation();\n };\n }\n\n protected connectedCallback(): void {\n super.connectedCallback();\n const lines =\n typeof this.#lines === \"function\" ? this.#lines() : this.#lines;\n this.#loading?.remove();\n if (lines instanceof Promise) {\n const buffer = (this.#loading = this.appendChild(new Buffer()));\n lines.then((line) => {\n //Closed or opened again before the lines arrived\n if (this.#loading !== buffer) return;\n this.#loading = undefined;\n buffer.remove();\n this.lines = line;\n this.set_position(this.#x, this.#y, this.#element);\n });\n } else {\n this.#loading = undefined;\n this.lines = lines;\n }\n this.addEventListener(\"focusout\", this.#focus_out_handler, {\n capture: true,\n });\n this.ownerDocument.defaultView?.addEventListener(\n \"resize\",\n this.#window_resize_handler,\n { passive: true },\n );\n }\n\n protected disconnectedCallback(): void {\n super.disconnectedCallback();\n //Lines arriving after the menu closed are not shown\n this.#loading?.remove();\n this.#loading = undefined;\n this.ownerDocument.defaultView?.removeEventListener(\n \"resize\",\n this.#window_resize_handler,\n );\n }\n\n /**Sets the lines of the context menu */\n set lines(lines: (ContextMenuLine | undefined)[]) {\n this.replaceChildren();\n if (this.#closer) this.appendChild(this.#closer);\n for (let i = 0; i < lines.length; i++) {\n const line = lines[i];\n if (line) this.appendChild(line as MenuLine);\n }\n }\n\n /**Changes focus to the next line\n * @param direction false is first child, true is last child */\n focus_next(direction: boolean) {\n //The direction is passed on, so a divider skips to the line after it, toward the middle\n if (direction) (this.lastChild as MenuLine)?.do_focus(true);\n else (this.firstChild as MenuLine)?.do_focus(false);\n }\n\n set closer(closer: boolean) {\n if (closer && !this.#closer) {\n this.classList.add(\"closer\");\n this.#closer = new MenuOption(\n \"Close\",\n () => {},\n material_close_rounded(),\n );\n this.#closer.onclick = (e) => {\n e.stopPropagation();\n if (this.parentElement instanceof MenuSub) {\n this.parentElement.close_down();\n } else {\n this.close_up();\n }\n };\n this.prepend(this.#closer);\n } else if (!closer && this.#closer) {\n this.classList.remove(\"closer\");\n this.#closer.remove();\n this.#closer = undefined;\n }\n }\n\n /**Sets the context menu to fullscreen mode in x directino */\n set fullscreenx(full: boolean) {\n if (full) this.classList.add(\"fullscreen-x\");\n else this.classList.remove(\"fullscreen-x\");\n }\n\n /**Sets the context menu to fullscreen mode in y direction */\n set fullscreeny(full: boolean) {\n if (full) this.classList.add(\"fullscreen-y\");\n else this.classList.remove(\"fullscreen-y\");\n }\n\n /**Closes the context menu down the tree*/\n close_down() {\n if (this.submenu) this.submenu.close_down();\n //@ts-expect-error Writing to readonly property, from inside class itself\n this.submenu = undefined;\n }\n\n /**Closes the context menu up the tree to the root*/\n close_up() {\n this.removeEventListener(\"focusout\", this.#focus_out_handler, {\n capture: true,\n });\n (this.parentElement as Container)?.close_up();\n this.remove();\n }\n\n /**Updates the position of the menu\n * @param x x coordinate for menu, this will be ignored if needed for contextmenu to fit\n * @param y y coordinate for menu, this will be ignored if needed for contextmenu to fit\n * @param element element to use instead of coordinates, the contextemenu will avoid covering the element if possible*/\n set_position(x: number = 0, y: number = 0, element?: Element) {\n this.#x = x;\n this.#y = y;\n this.#element = element;\n const box = this.getBoundingClientRect();\n const box_area = box.width * box.height;\n const window = this.ownerDocument.defaultView!;\n const html_area = window.innerWidth * window.innerHeight;\n this.closer = box_area > html_area * 0.5;\n let top = NaN;\n let bottom = NaN;\n let left = NaN;\n let right = NaN;\n if (element) {\n const sub_box = element.getBoundingClientRect();\n\n if (sub_box.x + sub_box.width + box.width > window.innerWidth) {\n x = sub_box.x;\n if (box.width < x) right = window.innerWidth - x;\n else right = window.innerWidth - (sub_box.x + sub_box.width);\n } else left = sub_box.x + sub_box.width;\n\n y = sub_box.y + sub_box.height;\n\n //Below the element, else above it, else as low as the window allows\n if (y + box.height < window.innerHeight) top = y;\n else if (sub_box.y >= box.height) bottom = window.innerHeight - sub_box.y;\n else top = Math.max(0, window.innerHeight - box.height);\n } else {\n if (y + box.height >= window.innerHeight) {\n if (y >= box.height) bottom = window.innerHeight - y;\n else top = window.innerHeight - box.height;\n } else top = y;\n\n if (box.width >= window.innerWidth) {\n right = 0;\n } else if (x + box.width >= window.innerWidth) {\n if (x >= box.width) right = window.innerWidth - x;\n else left = window.innerWidth - box.width;\n } else left = x;\n }\n this.fullscreenx = box.width === window.innerWidth;\n this.fullscreeny = box.height >= window.innerHeight;\n\n this.style.top = top === top ? top + \"px\" : \"\";\n this.style.bottom = bottom === bottom ? bottom + \"px\" : \"\";\n this.style.left = left === left ? left + \"px\" : \"\";\n this.style.right = right === right ? right + \"px\" : \"\";\n this.focus();\n }\n}\ndefine_element(ContextMenu);\n\nexport function context_menu(\n lines:\n | (\n | (ContextMenuLine | undefined)[]\n | Promise<(ContextMenuLine | undefined)[]>\n )\n | (() => (ContextMenuLine | undefined)[])\n | (() => Promise<(ContextMenuLine | undefined)[]>),\n): ContextMenu {\n return new ContextMenu(lines);\n}\n","import { context_devider } from \"./devider\";\nimport {\n context_menu_attach,\n context_menu_default,\n context_menu_detach,\n context_menu_summon,\n CONTEXT_MENY_SYMBOL,\n} from \"./engine\";\nimport { context_menu } from \"./menu\";\nimport { context_line } from \"./option\";\nimport { context_sub } from \"./submenu\";\n\nexport const ctm = {\n attach: context_menu_attach,\n default: context_menu_default,\n detach: context_menu_detach,\n summon: context_menu_summon,\n has(element: Element) {\n return Boolean(element[CONTEXT_MENY_SYMBOL]);\n },\n menu: context_menu,\n line: context_line,\n sub: context_sub,\n devider: context_devider,\n};\nexport default ctm;\n\nexport type { ContextMenu, ContextMenuLines } from \"./menu\";\n"],"mappings":";;;;;;;;AAGA,MAAM,YAAY,yBAChB,eACA,gBACA,uDACF;AACA,UAAU,cACR,cACA,oBACA,uBACA,KAAK,OACL,KAAK,QACL,SACA,KAAA,CACF;AACA,UAAU,cACR,QACA,cACA,iBACA,KAAK,QACL,KAAK,QACL,SACA,KAAA,CACF;AACA,UAAU,cACR,SACA,eACA,kDACA,KAAK,QACL,KAAK,QACL,SACA,KAAA,CACF;AACA,UAAU,cACR,aACA,cACA,uBACA,KAAK,QACL,KAAK,OACL,SACA,KAAA,CACF;AACA,UAAU,cACR,UACA,gBACA,gCACA,KAAK,QACL,KAAK,QACL,SACA,KAAA,CACF;;AC9CA,IAAsB,WAAtB,cAAuC,KAAgC;;CAErE,OAAO,eAAe;EACpB,OAAO;CACT;;CAEA,OAAO,qBAAqB;EAC1B,OAAO;CACT;;CAKA,IAAI,cAAc;EAChB,OAA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,IAAI,GAAG,OAAO,cAAc,IAAI,MAAM;EACxD,OAAO;GACL,IAAI,IAAI,IAAI,UAAU,OAAO,aAAa;IACxC,IAAI,KAAK,IAAI,QAAQ,SAAS,OAAO,cAAc;SAC9C,MAAM,OAAO,cAAc,IAAI;GACtC,OAAO,MAAM;GAEb,IAAI,IAAI,SAAS,OAAO,YACtB,QAAQ;QACH,IAAI,IAAI,IAAI,SAAS,OAAO,YAAY;IAC7C,IAAI,KAAK,IAAI,OAAO,QAAQ,OAAO,aAAa;SAC3C,OAAO,OAAO,aAAa,IAAI;GACtC,OAAO,OAAO;EAChB;EACA,KAAK,cAAc,IAAI,UAAU,OAAO;EACxC,KAAK,cAAc,IAAI,UAAU,OAAO;EAExC,KAAK,MAAM,MAAM,QAAQ,MAAM,MAAM,OAAO;EAC5C,KAAK,MAAM,SAAS,WAAW,SAAS,SAAS,OAAO;EACxD,KAAK,MAAM,OAAO,SAAS,OAAO,OAAO,OAAO;EAChD,KAAK,MAAM,QAAQ,UAAU,QAAQ,QAAQ,OAAO;EACpD,KAAK,MAAM;CACb;AACF;AACA,eAAe,WAAW;AAE1B,SAAgB,aACd,OAOa;CACb,OAAO,IAAI,YAAY,KAAK;AAC9B;;ACvPA,MAAa,MAAM;CACjB,QAAQ;CACR,SAAS;CACT,QAAQ;CACR,QAAQ;CACR,IAAI,SAAkB;EACpB,OAAO,QAAQ,QAAQ,oBAAoB;CAC7C;CACA,MAAM;CACN,MAAM;CACN,KAAK;CACL,SAAS;AACX"}
|
|
1
|
+
{"version":3,"file":"context-menu-Bo8R6DmK.mjs","names":[],"sources":["../src/context-menu/shared.ts","../src/context-menu/line.ts","../src/context-menu/devider.ts","../src/context-menu/container.ts","../src/context-menu/engine.ts","../src/context-menu/buffer.ts","../src/context-menu/option.ts","../src/context-menu/submenu.ts","../src/context-menu/menu.ts","../src/context-menu/index.ts"],"sourcesContent":["import { BLUE, GREY } from \"@chocbite/ts-lib/colors\";\nimport { theme_init_variable_root } from \"#theme\";\n\nconst variables = theme_init_variable_root(\n \"contextmenu\",\n \"Context Menu\",\n \"Right click or touch and hold context menu appearance\",\n);\nvariables.make_variable(\n \"background\",\n \"Background Color\",\n \"Color of background\",\n GREY[\"50\"],\n GREY[\"900\"],\n \"Color\",\n undefined,\n);\nvariables.make_variable(\n \"text\",\n \"Text Color\",\n \"Color of text\",\n GREY[\"600\"],\n GREY[\"400\"],\n \"Color\",\n undefined,\n);\nvariables.make_variable(\n \"hover\",\n \"Hover Color\",\n \"Background color of line when hovering over it\",\n BLUE[\"200\"],\n BLUE[\"900\"],\n \"Color\",\n undefined,\n);\nvariables.make_variable(\n \"hoverText\",\n \"Text Color\",\n \"Standard text color\",\n GREY[\"900\"],\n GREY[\"50\"],\n \"Color\",\n undefined,\n);\nvariables.make_variable(\n \"border\",\n \"Border Color\",\n \"Color of border and deviders\",\n GREY[\"300\"],\n GREY[\"800\"],\n \"Color\",\n undefined,\n);\n","import { Base } from \"#base\";\nimport \"./option.scss\";\nimport \"./shared\";\n\nexport interface ContextMenuLine {}\n\nexport abstract class MenuLine extends Base implements ContextMenuLine {\n /**Returns the name used to define the element */\n static element_name() {\n return \"@abstract@\";\n }\n /**Returns the namespace override for the element*/\n static element_name_space() {\n return \"contextmenu\";\n }\n\n abstract do_focus(dir?: boolean): void;\n\n /**True for lines that can not take focus, like dividers, focus moves past them*/\n get skips_focus() {\n return false;\n }\n\n /**Changes focus to the next line, wrapping around and skipping lines that can not take focus\n * @param direction false is next sibling, true is previous */\n focus_next(direction?: boolean) {\n const parent = this.parentElement;\n if (!parent) return;\n let line = direction\n ? this.previousElementSibling\n : this.nextElementSibling;\n for (;;) {\n line ??= direction ? parent.lastElementChild : parent.firstElementChild;\n //Back at the start, there is no other line to focus\n if (!line || line === this) return;\n if (!(line as MenuLine).skips_focus)\n return (line as MenuLine).do_focus(direction);\n line = direction ? line.previousElementSibling : line.nextElementSibling;\n }\n }\n}\n","import { define_element } from \"#base\";\nimport \"./devider.scss\";\nimport { ContextMenuLine, MenuLine } from \"./line\";\n\nexport interface ContextMenuDevider extends ContextMenuLine {}\n\nexport class Devider extends MenuLine implements ContextMenuDevider {\n /**Returns the name used to define the element */\n static element_name() {\n return \"devider\";\n }\n\n get skips_focus() {\n return true;\n }\n\n do_focus(dir?: boolean) {\n this.focus_next(dir);\n }\n}\ndefine_element(Devider);\n\nexport function context_devider(): ContextMenuDevider {\n return new Devider();\n}\n","import { Base, define_element } from \"#base\";\nimport \"./container.scss\";\nimport { ContextMenu } from \"./menu\";\n\nexport class Container extends Base {\n #active_element_buffer: HTMLOrSVGElement | null | undefined;\n #replacing = false;\n\n /**Returns the name used to define the element */\n static element_name() {\n return \"container\";\n }\n /**Returns the namespace override for the element*/\n static element_name_space() {\n return \"contextmenu\";\n }\n\n constructor() {\n super();\n this.tabIndex = -1;\n const preventer = (e: Event) => {\n e.preventDefault();\n e.stopPropagation();\n };\n this.oncontextmenu = preventer;\n this.onpointerdown = preventer;\n this.onpointerup = preventer;\n this.onpointercancel = preventer;\n this.onpointerenter = preventer;\n this.onpointerleave = preventer;\n this.onpointermove = preventer;\n this.onpointerout = preventer;\n this.onpointerout = preventer;\n this.onclick = preventer;\n }\n\n /**Attaches a menu to the container */\n attach_menu(menu: ContextMenu) {\n menu.container = this;\n const old = this.firstElementChild as ContextMenu | null;\n if (old) {\n //Closed before replacing, the browser closes it from a focusout while it is being removed otherwise,\n //focus still returns to the element from before the old menu\n this.#replacing = true;\n old.close_down();\n old.close_up();\n this.#replacing = false;\n } else\n this.#active_element_buffer = this.ownerDocument\n .activeElement as HTMLOrSVGElement | null;\n this.replaceChildren(menu);\n return menu;\n }\n\n /**Closes open context menu */\n close_up() {\n if (this.#replacing) return;\n if (this.#active_element_buffer) {\n this.#active_element_buffer.focus();\n if (\n (this.ownerDocument.activeElement as any) !==\n this.#active_element_buffer\n ) {\n this.focus();\n }\n this.#active_element_buffer = undefined;\n } else {\n this.focus();\n }\n }\n}\ndefine_element(Container);\n","import { DOCUMENT_HANDLER } from \"#document\";\nimport type { Option } from \"@chocbite/ts-lib/result\";\nimport { Container } from \"./container\";\nimport \"./engine.scss\";\nimport { ContextMenu } from \"./menu\";\n\nexport const CONTEXT_MENY_SYMBOL = Symbol(\"context_menu\");\n\ndeclare global {\n interface Document {\n [CONTEXT_MENY_SYMBOL]: Container | undefined;\n }\n interface Element {\n [CONTEXT_MENY_SYMBOL]: EventListenerOrEventListenerObject | undefined;\n }\n}\n\n/**Default context menu, false blocks the operating system context menu, undefined leaves it*/\nlet default_menu: ContextMenu | (() => Option<ContextMenu>) | false | undefined;\n\n/**Blocks the operating system context menu when the default is false*/\nconst block_os_menu = (e: Event) => e.preventDefault();\n\nDOCUMENT_HANDLER.events.on(\"added\", (e) => {\n apply_to_doc(e.data);\n});\nDOCUMENT_HANDLER.for_documents((doc) => {\n apply_to_doc(doc);\n});\n\nfunction apply_to_doc(doc: Document) {\n const container = new Container();\n doc[CONTEXT_MENY_SYMBOL] = container;\n doc.documentElement.appendChild(container);\n apply_default_to_doc(doc);\n}\n\n/**Applies the current default context menu to a document*/\nfunction apply_default_to_doc(doc: Document) {\n const root = doc.documentElement;\n context_menu_detach(root);\n root.removeEventListener(\"contextmenu\", block_os_menu);\n if (default_menu) context_menu_attach(root, default_menu);\n else if (default_menu === false)\n root.addEventListener(\"contextmenu\", block_os_menu);\n}\n\n/**Attaches a context menu to the given element\n * @param element the element to attach the context menu to\n * @param lines the context menu to attach, if a function is given it will be called when the context menu is summoned\n * @param block a function that returns true if the context menu should not be summoned, if undefined the context menu will always be summoned*/\nexport function context_menu_attach(\n element: Element,\n lines: ContextMenu | (() => Option<ContextMenu>),\n block?: () => boolean,\n) {\n if (element[CONTEXT_MENY_SYMBOL]) context_menu_detach(element);\n const listener = (e: Event) => {\n e.preventDefault();\n e.stopPropagation();\n if (block && block()) return;\n const lineses =\n typeof lines === \"function\" ? lines().unwrap_or(undefined) : lines;\n if (!lineses) return;\n context_menu_summon(\n lineses,\n element,\n (e as MouseEvent).clientX,\n (e as MouseEvent).clientY,\n );\n };\n element.addEventListener(\"contextmenu\", listener);\n element[CONTEXT_MENY_SYMBOL] = listener;\n}\n\n/**Dettaches the context menu from the given element */\nexport function context_menu_detach(element: Element) {\n if (element[CONTEXT_MENY_SYMBOL]) {\n element.removeEventListener(\"contextmenu\", element[CONTEXT_MENY_SYMBOL]);\n delete element[CONTEXT_MENY_SYMBOL];\n }\n}\n\n/**Summons a context menu at a given location\n * @param menu the context menu to summon\n * @param element the element the context menu is referenced to, if undefined the context menu will appear in the main document\n * @param x x position for context menu, if undefined, will use element middle, if element undefined, will put context menu in the top left corner of the screen\n * @param y y position for context menu, if undefined, will use element middle, if element undefined, will put context menu in the top left corner of the screen\n * @param dont_cover when set true */\nexport function context_menu_summon(\n menu: ContextMenu,\n element?: Element,\n x?: number,\n y?: number,\n dont_cover?: boolean,\n) {\n const container = element\n ? element.ownerDocument[CONTEXT_MENY_SYMBOL]\n : DOCUMENT_HANDLER.main[CONTEXT_MENY_SYMBOL];\n if (container) {\n if (typeof x !== \"number\" || typeof y !== \"number\") {\n if (element) {\n const box = element.getBoundingClientRect();\n x = box.left + box.width / 2;\n y = box.top + box.height / 2;\n } else {\n x = 0;\n y = 0;\n }\n }\n container\n .attach_menu(menu)\n .set_position(x, y, dont_cover ? element : undefined);\n } else console.error(\"No context menu container available\");\n}\n\n/**Sets the default context menu for the page, the one used if no other context menu has been attached to the element\n * If set to false the operating system context menu is disabled and nothing will appear\n * If set undefined the operating systems context menu will be used*/\nexport function context_menu_default(\n lines: ContextMenu | (() => Option<ContextMenu>) | false | undefined,\n) {\n default_menu = lines;\n DOCUMENT_HANDLER.for_documents(apply_default_to_doc);\n}\n","import { define_element } from \"#base\";\nimport { Spinner } from \"#spinner\";\nimport \"./buffer.scss\";\nimport { MenuLine } from \"./line\";\n\nexport class Buffer extends MenuLine {\n /**Returns the name used to define the element */\n static element_name() {\n return \"buffer\";\n }\n\n constructor() {\n super();\n this.appendChild(new Spinner());\n }\n\n get skips_focus() {\n return true;\n }\n\n do_focus(dir: boolean) {\n this.focus_next(dir);\n }\n}\ndefine_element(Buffer);\n","import { define_element } from \"#base\";\nimport { ContextMenuLine, MenuLine } from \"./line\";\nimport { ContextMenu } from \"./menu\";\nimport \"./option.scss\";\n\nexport interface ContextMenuOption extends ContextMenuLine {}\n\nexport class MenuOption extends MenuLine implements ContextMenuOption {\n readonly func: () => void;\n\n /**Returns the name used to define the element */\n static element_name() {\n return \"option\";\n }\n\n constructor(\n text: string,\n func: () => void,\n icon?: SVGSVGElement,\n shortcut?: string,\n checkmark?: boolean,\n ) {\n super();\n this.func = func;\n this.tabIndex = 0;\n const icon_box = this.appendChild(document.createElement(\"div\"));\n icon_box.className = \"icon\";\n if (icon) icon_box.appendChild(icon);\n const text_box = this.appendChild(document.createElement(\"div\"));\n text_box.textContent = text;\n text_box.className = \"text\";\n const shortcut_box = this.appendChild(document.createElement(\"div\"));\n if (shortcut) shortcut_box.textContent = shortcut;\n shortcut_box.className = \"shortcut\";\n const check_mark_box = this.appendChild(document.createElement(\"div\"));\n if (checkmark) check_mark_box.textContent = \"✓\";\n check_mark_box.className = \"checkmark\";\n\n this.onclick = (e) => {\n e.stopPropagation();\n this.func();\n navigator.vibrate?.(25);\n (this.parentElement as ContextMenu).close_up();\n };\n\n this.onkeydown = (e) => {\n switch (e.code) {\n case \"Tab\":\n case \"ArrowUp\":\n case \"ArrowDown\":\n this.focus_next(e.shiftKey || e.code === \"ArrowUp\");\n break;\n case \"Enter\":\n case \"Space\":\n this.func();\n (this.parentElement as ContextMenu).close_up();\n break;\n case \"ArrowLeft\":\n case \"Escape\":\n return;\n }\n e.preventDefault();\n e.stopPropagation();\n };\n }\n\n do_focus(): void {\n this.focus();\n }\n}\ndefine_element(MenuOption);\n\nexport function context_line(\n text: string,\n func: () => void,\n icon?: SVGSVGElement,\n shortcut?: string,\n checkmark?: boolean,\n): ContextMenuOption {\n return new MenuOption(text, func, icon, shortcut, checkmark);\n}\n","import { define_element } from \"#base\";\nimport { material_chevron_right_rounded } from \"#icons\";\nimport { ContextMenuLine, MenuLine } from \"./line\";\nimport { ContextMenu } from \"./menu\";\nimport \"./submenu.scss\";\n\nexport interface ContextMenuSub extends ContextMenuLine {}\n\ntype Mutable<T> = {\n -readonly [P in keyof T]: T[P];\n};\nexport class MenuSub extends MenuLine implements ContextMenuSub {\n #menu: ContextMenu;\n #is_open?: boolean;\n #hover_time?: number;\n #block_time?: number;\n\n /**Returns the name used to define the element */\n static element_name() {\n return \"submenu\";\n }\n\n constructor(text: string, menu: ContextMenu, icon?: SVGSVGElement) {\n super();\n this.#menu = menu;\n this.tabIndex = 0;\n const icon_box = this.appendChild(document.createElement(\"div\"));\n icon_box.className = \"icon\";\n if (icon) icon_box.appendChild(icon);\n const text_box = this.appendChild(document.createElement(\"div\"));\n text_box.textContent = text;\n text_box.className = \"text\";\n const shortcut_box = this.appendChild(document.createElement(\"div\"));\n shortcut_box.className = \"shortcut\";\n const chevron_box = this.appendChild(document.createElement(\"div\"));\n chevron_box.appendChild(material_chevron_right_rounded());\n chevron_box.className = \"chevron\";\n\n this.onclick = (e) => {\n e.stopPropagation();\n if (!this.#block_time) {\n navigator.vibrate?.(25);\n if (this.#is_open) {\n this.close_down();\n } else {\n this.open();\n }\n }\n };\n\n this.onpointerenter = (e) => {\n if (e.pointerType !== \"touch\" && !this.#is_open) {\n this.#hover_time = window.setTimeout(() => {\n this.open();\n this.#block_time = window.setTimeout(() => {\n this.#block_time = 0;\n }, 500);\n }, 300);\n }\n };\n this.onpointerleave = () => {\n clearTimeout(this.#hover_time);\n };\n this.onkeydown = (e) => {\n switch (e.code) {\n case \"Tab\":\n case \"ArrowUp\":\n case \"ArrowDown\":\n this.focus_next(e.shiftKey || e.code === \"ArrowUp\");\n break;\n case \"ArrowRight\":\n case \"Enter\":\n case \"Space\":\n this.open();\n this.#menu.focus_next(false);\n break;\n case \"ArrowLeft\":\n case \"Escape\":\n return;\n }\n e.preventDefault();\n e.stopPropagation();\n };\n }\n\n /**Opens the sub menu */\n open() {\n const sub = this.parentElement as Mutable<ContextMenu>;\n if (sub) sub.close_down();\n (this.parentElement as Mutable<ContextMenu>).submenu = this;\n this.appendChild(this.#menu);\n this.#menu.set_position(0, 0, this);\n this.#is_open = true;\n }\n\n do_focus(): void {\n this.focus();\n }\n\n /**Closes menu by calling parent*/\n close() {\n this.focus();\n (this.parentElement as Mutable<ContextMenu>).submenu = undefined;\n this.removeChild(this.#menu);\n this.#is_open = false;\n }\n\n /**Closes the context menu down the tree*/\n close_down() {\n this.#menu.close_down();\n this.close();\n }\n\n /**Closes the context menu up the tree to the root*/\n close_up() {\n this.close();\n (this.parentElement as ContextMenu).close_up();\n }\n}\ndefine_element(MenuSub);\n\nexport function context_sub(\n text: string,\n menu: ContextMenu,\n icon?: SVGSVGElement,\n): ContextMenuSub {\n return new MenuSub(text, menu, icon);\n}\n","import { Base, define_element } from \"#base\";\nimport { material_close_rounded } from \"#icons\";\nimport { Buffer } from \"./buffer\";\nimport { Container } from \"./container\";\nimport { ContextMenuLine, MenuLine } from \"./line\";\nimport \"./menu.scss\";\nimport { MenuOption } from \"./option\";\nimport \"./shared\";\nimport { MenuSub } from \"./submenu\";\n\nexport type ContextMenuLines = ContextMenuLine[];\n\nexport class ContextMenu extends Base {\n /**Returns the name used to define the element */\n static element_name() {\n return \"menu\";\n }\n /**Returns the namespace override for the element*/\n static element_name_space() {\n return \"contextmenu\";\n }\n\n container: Container | undefined;\n readonly submenu: MenuSub | undefined;\n #closer: MenuOption | undefined;\n #x: number | undefined;\n #y: number | undefined;\n #element: Element | undefined;\n /**Spinner shown while promised lines load, cleared when the menu closes*/\n #loading: Buffer | undefined;\n #focus_out_handler = (e: FocusEvent) => {\n e.preventDefault();\n e.stopPropagation();\n if (!e.relatedTarget || !this.contains(e.relatedTarget as Node)) {\n this.close_up();\n this.close_down();\n }\n };\n #window_resize_handler = () => {\n this.set_position(this.#x, this.#y, this.#element);\n };\n\n #lines:\n | (\n | (ContextMenuLine | undefined)[]\n | Promise<(ContextMenuLine | undefined)[]>\n )\n | (() =>\n | (ContextMenuLine | undefined)[]\n | Promise<(ContextMenuLine | undefined)[]>);\n\n constructor(\n lines:\n | (\n | (ContextMenuLine | undefined)[]\n | Promise<(ContextMenuLine | undefined)[]>\n )\n | (() =>\n | (ContextMenuLine | undefined)[]\n | Promise<(ContextMenuLine | undefined)[]>),\n ) {\n super();\n this.#lines = lines;\n this.tabIndex = 0;\n this.onscroll = () => {\n this.close_down();\n };\n this.onkeydown = (e) => {\n if (e.code === \"Tab\" || e.code === \"ArrowUp\" || e.code === \"ArrowDown\")\n this.focus_next(e.shiftKey || e.code === \"ArrowUp\");\n else if (e.code === \"ArrowLeft\") {\n const parent = this.parentElement as MenuSub | Container;\n if (!(parent instanceof Container)) {\n parent.focus();\n parent.close_down();\n }\n } else if (e.code === \"Escape\") this.close_up();\n e.preventDefault();\n e.stopPropagation();\n };\n }\n\n protected connectedCallback(): void {\n super.connectedCallback();\n const lines =\n typeof this.#lines === \"function\" ? this.#lines() : this.#lines;\n this.#loading?.remove();\n if (lines instanceof Promise) {\n const buffer = (this.#loading = this.appendChild(new Buffer()));\n lines.then((line) => {\n //Closed or opened again before the lines arrived\n if (this.#loading !== buffer) return;\n this.#loading = undefined;\n buffer.remove();\n this.lines = line;\n this.set_position(this.#x, this.#y, this.#element);\n });\n } else {\n this.#loading = undefined;\n this.lines = lines;\n }\n this.addEventListener(\"focusout\", this.#focus_out_handler, {\n capture: true,\n });\n this.ownerDocument.defaultView?.addEventListener(\n \"resize\",\n this.#window_resize_handler,\n { passive: true },\n );\n }\n\n protected disconnectedCallback(): void {\n super.disconnectedCallback();\n //Lines arriving after the menu closed are not shown\n this.#loading?.remove();\n this.#loading = undefined;\n this.ownerDocument.defaultView?.removeEventListener(\n \"resize\",\n this.#window_resize_handler,\n );\n }\n\n /**Sets the lines of the context menu */\n set lines(lines: (ContextMenuLine | undefined)[]) {\n this.replaceChildren();\n if (this.#closer) this.appendChild(this.#closer);\n for (let i = 0; i < lines.length; i++) {\n const line = lines[i];\n if (line) this.appendChild(line as MenuLine);\n }\n }\n\n /**Changes focus to the next line\n * @param direction false is first child, true is last child */\n focus_next(direction: boolean) {\n //The direction is passed on, so a divider skips to the line after it, toward the middle\n if (direction) (this.lastChild as MenuLine)?.do_focus(true);\n else (this.firstChild as MenuLine)?.do_focus(false);\n }\n\n set closer(closer: boolean) {\n if (closer && !this.#closer) {\n this.classList.add(\"closer\");\n this.#closer = new MenuOption(\n \"Close\",\n () => {},\n material_close_rounded(),\n );\n this.#closer.onclick = (e) => {\n e.stopPropagation();\n if (this.parentElement instanceof MenuSub) {\n this.parentElement.close_down();\n } else {\n this.close_up();\n }\n };\n this.prepend(this.#closer);\n } else if (!closer && this.#closer) {\n this.classList.remove(\"closer\");\n this.#closer.remove();\n this.#closer = undefined;\n }\n }\n\n /**Sets the context menu to fullscreen mode in x directino */\n set fullscreenx(full: boolean) {\n if (full) this.classList.add(\"fullscreen-x\");\n else this.classList.remove(\"fullscreen-x\");\n }\n\n /**Sets the context menu to fullscreen mode in y direction */\n set fullscreeny(full: boolean) {\n if (full) this.classList.add(\"fullscreen-y\");\n else this.classList.remove(\"fullscreen-y\");\n }\n\n /**Closes the context menu down the tree*/\n close_down() {\n if (this.submenu) this.submenu.close_down();\n //@ts-expect-error Writing to readonly property, from inside class itself\n this.submenu = undefined;\n }\n\n /**Closes the context menu up the tree to the root*/\n close_up() {\n this.removeEventListener(\"focusout\", this.#focus_out_handler, {\n capture: true,\n });\n (this.parentElement as Container)?.close_up();\n this.remove();\n }\n\n /**Updates the position of the menu\n * @param x x coordinate for menu, this will be ignored if needed for contextmenu to fit\n * @param y y coordinate for menu, this will be ignored if needed for contextmenu to fit\n * @param element element to use instead of coordinates, the contextemenu will avoid covering the element if possible*/\n set_position(x: number = 0, y: number = 0, element?: Element) {\n this.#x = x;\n this.#y = y;\n this.#element = element;\n const box = this.getBoundingClientRect();\n const box_area = box.width * box.height;\n const window = this.ownerDocument.defaultView!;\n const html_area = window.innerWidth * window.innerHeight;\n this.closer = box_area > html_area * 0.5;\n let top = NaN;\n let bottom = NaN;\n let left = NaN;\n let right = NaN;\n if (element) {\n const sub_box = element.getBoundingClientRect();\n\n if (sub_box.x + sub_box.width + box.width > window.innerWidth) {\n x = sub_box.x;\n if (box.width < x) right = window.innerWidth - x;\n else right = window.innerWidth - (sub_box.x + sub_box.width);\n } else left = sub_box.x + sub_box.width;\n\n y = sub_box.y + sub_box.height;\n\n //Below the element, else above it, else as low as the window allows\n if (y + box.height < window.innerHeight) top = y;\n else if (sub_box.y >= box.height) bottom = window.innerHeight - sub_box.y;\n else top = Math.max(0, window.innerHeight - box.height);\n } else {\n if (y + box.height >= window.innerHeight) {\n if (y >= box.height) bottom = window.innerHeight - y;\n else top = window.innerHeight - box.height;\n } else top = y;\n\n if (box.width >= window.innerWidth) {\n right = 0;\n } else if (x + box.width >= window.innerWidth) {\n if (x >= box.width) right = window.innerWidth - x;\n else left = window.innerWidth - box.width;\n } else left = x;\n }\n this.fullscreenx = box.width === window.innerWidth;\n this.fullscreeny = box.height >= window.innerHeight;\n\n this.style.top = top === top ? top + \"px\" : \"\";\n this.style.bottom = bottom === bottom ? bottom + \"px\" : \"\";\n this.style.left = left === left ? left + \"px\" : \"\";\n this.style.right = right === right ? right + \"px\" : \"\";\n this.focus();\n }\n}\ndefine_element(ContextMenu);\n\nexport function context_menu(\n lines:\n | (\n | (ContextMenuLine | undefined)[]\n | Promise<(ContextMenuLine | undefined)[]>\n )\n | (() => (ContextMenuLine | undefined)[])\n | (() => Promise<(ContextMenuLine | undefined)[]>),\n): ContextMenu {\n return new ContextMenu(lines);\n}\n","import { context_devider } from \"./devider\";\nimport {\n context_menu_attach,\n context_menu_default,\n context_menu_detach,\n context_menu_summon,\n CONTEXT_MENY_SYMBOL,\n} from \"./engine\";\nimport { context_menu } from \"./menu\";\nimport { context_line } from \"./option\";\nimport { context_sub } from \"./submenu\";\n\nexport const ctm = {\n attach: context_menu_attach,\n default: context_menu_default,\n detach: context_menu_detach,\n summon: context_menu_summon,\n has(element: Element) {\n return Boolean(element[CONTEXT_MENY_SYMBOL]);\n },\n menu: context_menu,\n line: context_line,\n sub: context_sub,\n devider: context_devider,\n};\nexport default ctm;\n\nexport type { ContextMenu, ContextMenuLines } from \"./menu\";\n"],"mappings":";;;;;;;;AAGA,MAAM,YAAY,yBAChB,eACA,gBACA,uDACF;AACA,UAAU,cACR,cACA,oBACA,uBACA,KAAK,OACL,KAAK,QACL,SACA,KAAA,CACF;AACA,UAAU,cACR,QACA,cACA,iBACA,KAAK,QACL,KAAK,QACL,SACA,KAAA,CACF;AACA,UAAU,cACR,SACA,eACA,kDACA,KAAK,QACL,KAAK,QACL,SACA,KAAA,CACF;AACA,UAAU,cACR,aACA,cACA,uBACA,KAAK,QACL,KAAK,OACL,SACA,KAAA,CACF;AACA,UAAU,cACR,UACA,gBACA,gCACA,KAAK,QACL,KAAK,QACL,SACA,KAAA,CACF;;AC9CA,IAAsB,WAAtB,cAAuC,KAAgC;;CAErE,OAAO,eAAe;EACpB,OAAO;CACT;;CAEA,OAAO,qBAAqB;EAC1B,OAAO;CACT;;CAKA,IAAI,cAAc;EAChB,OAAO;CACT;;;CAIA,WAAW,WAAqB;EAC9B,MAAM,SAAS,KAAK;EACpB,IAAI,CAAC,QAAQ;EACb,IAAI,OAAO,YACP,KAAK,yBACL,KAAK;EACT,SAAS;GACP,SAAS,YAAY,OAAO,mBAAmB,OAAO;GAEtD,IAAI,CAAC,QAAQ,SAAS,MAAM;GAC5B,IAAI,CAAE,KAAkB,aACtB,OAAQ,KAAkB,SAAS,SAAS;GAC9C,OAAO,YAAY,KAAK,yBAAyB,KAAK;EACxD;CACF;AACF;;AClCA,IAAa,UAAb,cAA6B,SAAuC;;CAElE,OAAO,eAAe;EACpB,OAAO;CACT;CAEA,IAAI,cAAc;EAChB,OAAO;CACT;CAEA,SAAS,KAAe;EACtB,KAAK,WAAW,GAAG;CACrB;AACF;A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,MAAM,MAAM,OAAO;EAC5C,KAAK,MAAM,SAAS,WAAW,SAAS,SAAS,OAAO;EACxD,KAAK,MAAM,OAAO,SAAS,OAAO,OAAO,OAAO;EAChD,KAAK,MAAM,QAAQ,UAAU,QAAQ,QAAQ,OAAO;EACpD,KAAK,MAAM;CACb;AACF;AACA,eAAe,WAAW;AAE1B,SAAgB,aACd,OAOa;CACb,OAAO,IAAI,YAAY,KAAK;AAC9B;;ACvPA,MAAa,MAAM;CACjB,QAAQ;CACR,SAAS;CACT,QAAQ;CACR,QAAQ;CACR,IAAI,SAAkB;EACpB,OAAO,QAAQ,QAAQ,oBAAoB;CAC7C;CACA,MAAM;CACN,MAAM;CACN,KAAK;CACL,SAAS;AACX"}
|
package/form/index.d.mts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import '../style.css';
|
|
2
|
-
import { l as Base, p as AccessTypes } from "../index-
|
|
3
|
-
import { t as SVGFunc } from "../index-
|
|
4
|
-
import { n as ListField } from "../index-
|
|
2
|
+
import { l as Base, p as AccessTypes } from "../index-ClfL2SQR.mjs";
|
|
3
|
+
import { t as SVGFunc } from "../index-ClIBfrHy.mjs";
|
|
4
|
+
import { n as ListField } from "../index-BTUFkF9s.mjs";
|
|
5
5
|
import { State, StateEnumRelated, StateNumberRelated, StateREAW, StateStringRelated } from "@chocbite/ts-lib/state";
|
|
6
6
|
import { Option, Result } from "@chocbite/ts-lib/result";
|
|
7
7
|
import { IPAddress, IPVersion, Prettify } from "@chocbite/ts-lib/common";
|
package/form/index.mjs
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import "../style.css";
|
|
2
2
|
import { AccessTypes, Base, define_element } from "../base/index.mjs";
|
|
3
|
-
import { c as ANIMATION_SPEED, i as theme_init_variable_root, l as AnimationLevels, s as ANIMATION_LEVEL } from "../theme-
|
|
3
|
+
import { c as ANIMATION_SPEED, i as theme_init_variable_root, l as AnimationLevels, s as ANIMATION_LEVEL } from "../theme-DgVtLDzP.mjs";
|
|
4
4
|
import { node_clone } from "../dom/index.mjs";
|
|
5
5
|
import { B1 as material_remove_rounded, Fx as material_drag_handle_rounded, Qot as material_unfold_less_rounded, U2 as material_schedule_rounded, dn as material_add_rounded, est as material_unfold_more_rounded, if as material_calendar_month_rounded, xI as material_keyboard_arrow_down_rounded, xh as material_close_rounded } from "../icons-e2J_Ojic.mjs";
|
|
6
|
-
import { n as ListField } from "../list-
|
|
6
|
+
import { n as ListField } from "../list-DOXIQOEY.mjs";
|
|
7
7
|
import { get_cursor_position, set_cursor_end, set_cursor_position, set_selection_all } from "../selection/index.mjs";
|
|
8
8
|
import { DOCUMENT_HANDLER } from "../document/index.mjs";
|
|
9
9
|
import state from "@chocbite/ts-lib/state";
|
package/icons/index.d.mts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import '../style.css';
|
|
2
|
-
import { t as SVGFunc } from "../index-
|
|
2
|
+
import { t as SVGFunc } from "../index-ClIBfrHy.mjs";
|
|
3
3
|
export declare const material_10k_rounded: SVGFunc;
|
|
4
4
|
export declare const material_10mp_rounded: SVGFunc;
|
|
5
5
|
export declare const material_11mp_rounded: SVGFunc;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import './style.css';
|
|
2
|
-
import { l as Base, u as BaseIntersectObserver } from "./index-
|
|
3
|
-
import { t as SVGFunc } from "./index-
|
|
4
|
-
import { n as ContextMenu } from "./index-
|
|
2
|
+
import { l as Base, u as BaseIntersectObserver } from "./index-ClfL2SQR.mjs";
|
|
3
|
+
import { t as SVGFunc } from "./index-ClIBfrHy.mjs";
|
|
4
|
+
import { n as ContextMenu } from "./index-Pr2sLv9e.mjs";
|
|
5
5
|
import { State } from "@chocbite/ts-lib/state";
|
|
6
6
|
import { Option, Result } from "@chocbite/ts-lib/result";
|
|
7
7
|
declare abstract class ListField extends Base {
|
|
@@ -170,4 +170,4 @@ declare const list: {
|
|
|
170
170
|
node_field: typeof node_field;
|
|
171
171
|
};
|
|
172
172
|
export { ListField as n, list as t };
|
|
173
|
-
//# sourceMappingURL=index-
|
|
173
|
+
//# sourceMappingURL=index-BTUFkF9s.d.mts.map
|
|
@@ -143,7 +143,7 @@ declare const svg: {
|
|
|
143
143
|
text: typeof text;
|
|
144
144
|
multi_line_text: typeof multi_line_text;
|
|
145
145
|
isosceles_triangle: typeof isosceles_triangle;
|
|
146
|
-
angle_to_anchor_point: (angle: number) => 0 |
|
|
146
|
+
angle_to_anchor_point: (angle: number) => 0 | 2 | 1 | 3 | 4 | 5 | 6 | 7;
|
|
147
147
|
};
|
|
148
148
|
type SVGFunc = () => SVGSVGElement;
|
|
149
149
|
declare global {
|
|
@@ -153,4 +153,4 @@ declare global {
|
|
|
153
153
|
}
|
|
154
154
|
}
|
|
155
155
|
export { svg as n, SVGAnchorPoint as r, SVGFunc as t };
|
|
156
|
-
//# sourceMappingURL=index-
|
|
156
|
+
//# sourceMappingURL=index-ClIBfrHy.d.mts.map
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import './style.css';
|
|
2
|
-
import { t as SVGFunc } from "./index-
|
|
2
|
+
import { t as SVGFunc } from "./index-ClIBfrHy.mjs";
|
|
3
3
|
import { State, StateInferSub, StateREA, StateROA, StateSub } from "@chocbite/ts-lib/state";
|
|
4
4
|
import { Option } from "@chocbite/ts-lib/result";
|
|
5
5
|
/**Enum of possible access types for base element*/
|
|
@@ -216,4 +216,4 @@ declare const ELEMENT_LIST: Set<string>;
|
|
|
216
216
|
/**Defines elements inheriting from the base*/
|
|
217
217
|
declare const define_element: (element: ElementConstructor) => void;
|
|
218
218
|
export { validate_element_name as a, base_loop as c, BaseIntersectObserverOptions as d, ACCESSTYPESINFO as f, set_base_element_global_namespace as i, Base as l, base_element_name as n, BaseSVG as o, AccessTypes as p, define_element as r, Loop as s, ELEMENT_LIST as t, BaseIntersectObserver as u };
|
|
219
|
-
//# sourceMappingURL=index-
|
|
219
|
+
//# sourceMappingURL=index-ClfL2SQR.d.mts.map
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import './style.css';
|
|
2
|
-
import { l as Base } from "./index-
|
|
2
|
+
import { l as Base } from "./index-ClfL2SQR.mjs";
|
|
3
3
|
import { Option } from "@chocbite/ts-lib/result";
|
|
4
4
|
interface ContextMenuLine {}
|
|
5
5
|
declare abstract class MenuLine extends Base implements ContextMenuLine {
|
|
@@ -119,4 +119,4 @@ declare const ctm: {
|
|
|
119
119
|
devider: typeof context_devider;
|
|
120
120
|
};
|
|
121
121
|
export { ContextMenu as n, ContextMenuLines as r, ctm as t };
|
|
122
|
-
//# sourceMappingURL=index-
|
|
122
|
+
//# sourceMappingURL=index-Pr2sLv9e.d.mts.map
|
package/keyboard/index.d.mts
CHANGED
package/keyboard/index.mjs
CHANGED
|
@@ -2,7 +2,7 @@ import "../style.css";
|
|
|
2
2
|
import { DOCUMENT_HANDLER } from "../document/index.mjs";
|
|
3
3
|
import { Base, define_element } from "../base/index.mjs";
|
|
4
4
|
import { get_cursor_position, set_cursor_position } from "../selection/index.mjs";
|
|
5
|
-
import { _ as version, i as theme_init_variable_root } from "../theme-
|
|
5
|
+
import { _ as version, i as theme_init_variable_root } from "../theme-DgVtLDzP.mjs";
|
|
6
6
|
import { settings_init } from "../settings/index.mjs";
|
|
7
7
|
import state, { state as state$1 } from "@chocbite/ts-lib/state";
|
|
8
8
|
import { some } from "@chocbite/ts-lib/result";
|
package/list/index.d.mts
CHANGED
package/list/index.mjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
import "../style.css";
|
|
2
|
-
export { n as ListField, t as default, t as list } from "../list-
|
|
2
|
+
export { n as ListField, t as default, t as list } from "../list-DOXIQOEY.mjs";
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import "./style.css";
|
|
2
2
|
import { Base, define_element } from "./base/index.mjs";
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import { t as ctm } from "./context-menu-
|
|
3
|
+
import { a as px_to_rem, i as theme_init_variable_root } from "./theme-DgVtLDzP.mjs";
|
|
4
|
+
import { t as state_ui } from "./state_ui-Bm3TeKNL.mjs";
|
|
5
|
+
import { t as ctm } from "./context-menu-Bo8R6DmK.mjs";
|
|
6
6
|
import { state as state$1 } from "@chocbite/ts-lib/state";
|
|
7
7
|
import { none, some } from "@chocbite/ts-lib/result";
|
|
8
8
|
import { GREY, ORANGE, RED } from "@chocbite/ts-lib/colors";
|
|
@@ -712,4 +712,4 @@ const list = {
|
|
|
712
712
|
};
|
|
713
713
|
export { ListField as n, list as t };
|
|
714
714
|
|
|
715
|
-
//# sourceMappingURL=list-
|
|
715
|
+
//# sourceMappingURL=list-DOXIQOEY.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"list-DOXIQOEY.mjs","names":["state","state","state","state"],"sources":["../src/list/key_field.ts","../src/list/add_row.ts","../src/list/error.ts","../src/list/field.ts","../src/list/row.ts","../src/list/shared.ts","../src/list/container.ts","../src/list/types.ts","../src/list/index.ts"],"sourcesContent":["import { Base, define_element } from \"#base\";\nimport { array_from_length } from \"@chocbite/ts-lib/common\";\nimport { none, some } from \"@chocbite/ts-lib/result\";\nimport { state, type State } from \"@chocbite/ts-lib/state\";\nimport type { SVGFunc } from \"#svg\";\nimport \"./key_field.scss\";\nimport type { ListRowParent, ListType } from \"./types\";\n\nexport interface ListKeyFieldOptions {\n icon?: SVGFunc | State<SVGFunc>;\n}\n\nexport class ListKeyField<A extends ListType<any>> extends Base {\n static element_name() {\n return \"keyfield\";\n }\n static element_name_space() {\n return \"list\";\n }\n\n #opener: HTMLDivElement;\n #text_box?: HTMLSpanElement;\n #icon?: SVGSVGElement;\n\n constructor(parent: ListRowParent<A>) {\n super();\n this.tabIndex = 0;\n this.onkeydown = (e) => {\n if (e.key === \"Enter\" || e.key === \" \") parent.open = !parent.open;\n else if (e.key === \"ArrowRight\") parent.open = true;\n else if (e.key === \"ArrowLeft\") parent.open = false;\n else if (e.key === \"ArrowDown\") parent.select_adjacent(\"next\", none());\n else if (e.key === \"ArrowUp\") parent.select_adjacent(\"previous\", none());\n else return;\n e.preventDefault();\n };\n\n const opener_box = document.createElement(\"span\");\n this.#opener = opener_box.appendChild(document.createElement(\"div\"));\n this.replaceChildren(\n ...array_from_length(parent.depth, (i) => {\n const div = document.createElement(\"div\");\n div.style.borderColor = \"var(--i-\" + i + \")\";\n return div;\n }),\n opener_box,\n );\n\n this.#opener.addEventListener(\"click\", (e) => {\n e.stopPropagation();\n e.preventDefault();\n parent.open = !parent.open;\n });\n }\n\n set options(options: ListKeyFieldOptions | undefined) {\n if (state.is.state(options?.icon)) {\n this.attach_state_to_prop(\"icon\", options.icon, () => some(undefined));\n } else this.detach_state_from_prop(\"icon\").icon = options?.icon;\n }\n\n set icon(value: SVGFunc | undefined) {\n if (this.#icon) this.#icon.remove();\n this.#icon = undefined;\n if (!value) return;\n this.#icon = value();\n if (this.#text_box) this.insertBefore(this.#icon, this.#text_box);\n else this.appendChild(this.#icon);\n }\n\n // ____ _____ ______ _ _ _____ _ _ _____\n // / __ \\| __ \\| ____| \\ | |_ _| \\ | |/ ____|\n // | | | | |__) | |__ | \\| | | | | \\| | | __\n // | | | | ___/| __| | . ` | | | | . ` | | |_ |\n // | |__| | | | |____| |\\ |_| |_| |\\ | |__| |\n // \\____/|_| |______|_| \\_|_____|_| \\_|\\_____|\n\n set openable(value: boolean) {\n if (value) this.classList.add(\"openable\");\n else this.classList.remove(\"openable\");\n }\n get openable(): boolean {\n return this.classList.contains(\"openable\");\n }\n}\ndefine_element(ListKeyField);\n","import { Base, define_element } from \"#base\";\nimport { some } from \"@chocbite/ts-lib/result\";\nimport { state, type State } from \"@chocbite/ts-lib/state\";\nimport type { SVGFunc } from \"#svg\";\nimport \"./add_row.scss\";\nimport { ListKeyField } from \"./key_field\";\nimport type {\n ListParentRows,\n ListRoot,\n ListRowParent,\n ListType,\n} from \"./types\";\n\nexport interface ListAddRowOptions {\n text: string | State<string>;\n disabled?: boolean | State<boolean>;\n icon?: SVGFunc | State<SVGFunc>;\n on_add: () => void;\n}\n\nexport class ListAddRow<\n R,\n T extends {},\n A extends ListType<any>,\n S extends boolean,\n>\n extends Base\n implements ListRowParent<A>\n{\n static element_name() {\n return \"addrow\";\n }\n static element_name_space(): string {\n return \"list\";\n }\n\n #button: HTMLSpanElement;\n #text: Text;\n #icon?: SVGSVGElement;\n #parent: ListRowParent<A>;\n readonly depth: number;\n\n constructor(root: ListRoot<R, T, A, S>, parent: ListRowParent<A>) {\n super();\n this.#parent = parent;\n this.depth = parent.depth + 1;\n if (root.sub_rows) this.appendChild(new ListKeyField(this));\n this.#button = this.appendChild(document.createElement(\"span\"));\n this.#button.tabIndex = 0;\n this.#text = this.#button.appendChild(document.createTextNode(\"\"));\n }\n\n set options(options: ListAddRowOptions) {\n this.#button.onclick = options.on_add;\n\n if (state.is.state(options.text))\n this.attach_state_to_prop(\"text\", options.text, (e) => some(e));\n else this.detach_state_from_prop(\"text\").text = options.text;\n if (state.is.state(options.disabled))\n this.attach_state_to_prop(\"disabled\", options.disabled, () =>\n some(false),\n );\n else this.detach_state_from_prop(\"disabled\").disabled = Boolean(\n options.disabled,\n );\n if (state.is.state(options.icon))\n this.attach_state_to_prop(\"icon\", options.icon, () => some(undefined));\n else this.detach_state_from_prop(\"icon\").icon = options.icon;\n }\n\n set text(value: string) {\n this.#text.data = value;\n }\n\n set icon(value: SVGFunc | undefined) {\n this.#icon?.remove();\n this.#icon = value ? this.#button.insertBefore(value(), this.#text) : undefined;\n }\n\n set disabled(value: boolean) {\n if (value) this.inert = true;\n else this.inert = false;\n }\n\n set open(_value: boolean) {}\n get open(): boolean {\n return false;\n }\n\n set global_index(_value: number) {}\n get global_index(): number {\n return 0;\n }\n\n /**Rows the add row adds to, the state of its parent */\n set state(_value: ListParentRows<A>) {}\n get state(): ListParentRows<A> {\n return this.#parent.state;\n }\n\n get global_amount(): number {\n return 0;\n }\n\n select_adjacent(): void {}\n}\ndefine_element(ListAddRow);\n","import { Base, define_element } from \"#base\";\nimport \"./error.scss\";\nimport { ListKeyField } from \"./key_field\";\nimport type { ListParentRows, ListRowParent, ListType } from \"./types\";\n\n/**Error text shown instead of the fields of an invalid row */\nexport class ListError extends Base {\n static element_name() {\n return \"error\";\n }\n static element_name_space() {\n return \"list\";\n }\n\n set text(value: string) {\n this.textContent = value;\n }\n}\ndefine_element(ListError);\n\n/**Error text shown instead of the rows of a parent, has a key field to continue the tree lines like an add row */\nexport class ListRowsError<A extends ListType<any>>\n extends Base\n implements ListRowParent<A>\n{\n static element_name() {\n return \"rowserror\";\n }\n static element_name_space() {\n return \"list\";\n }\n\n #text = new ListError();\n #parent: ListRowParent<A>;\n readonly depth: number;\n\n constructor(sub_rows: boolean, parent: ListRowParent<A>) {\n super();\n this.#parent = parent;\n this.depth = parent.depth + 1;\n if (sub_rows) this.appendChild(new ListKeyField(this));\n this.appendChild(this.#text);\n }\n\n set text(value: string) {\n this.#text.text = value;\n }\n\n set open(_value: boolean) {}\n get open(): boolean {\n return false;\n }\n\n /**Rows the error is shown for, the state of its parent */\n set state(_value: ListParentRows<A>) {}\n get state(): ListParentRows<A> {\n return this.#parent.state;\n }\n\n select_adjacent(): void {}\n}\ndefine_element(ListRowsError);\n\n/**Shows the text in an error element directly after the row box, removes the element when there is no text\n * @returns the element to give next time, undefined when there is no text*/\nexport function list_rows_error_update<A extends ListType<any>>(\n row_box: Element,\n current: ListRowsError<A> | undefined,\n text: string | undefined,\n sub_rows: boolean,\n parent: ListRowParent<A>,\n): ListRowsError<A> | undefined {\n if (text === undefined) {\n current?.remove();\n return undefined;\n }\n if (!current) {\n current = new ListRowsError(sub_rows, parent);\n //Not in the row box, everything in there is a row\n row_box.after(current);\n }\n current.text = text;\n return current;\n}\n","import { Base, define_element } from \"#base\";\nimport \"./field.scss\";\nimport type { ListColumnAlign } from \"./types\";\n\n/**Adds the class for the alignment, center is the default and adds nothing\n * Only the styling of an element decides if the class does anything, so complex fields just do not follow it */\nexport function list_align_apply(\n element: HTMLElement,\n align: ListColumnAlign | undefined,\n) {\n if (align === \"left\" || align === \"right\")\n element.classList.add(\"align-\" + align);\n}\n\nexport abstract class ListField extends Base {\n static element_name() {\n return \"@abstract@\";\n }\n static element_name_space() {\n return \"list\";\n }\n\n constructor() {\n super();\n }\n}\n\nexport class ListTextField extends ListField {\n static element_name() {\n return \"textfield\";\n }\n\n set text(value: string) {\n this.textContent = value;\n }\n}\ndefine_element(ListTextField);\n\nexport function text_field() {\n return new ListTextField();\n}\n\nexport class ListNumberField extends ListField {\n static element_name() {\n return \"numberfield\";\n }\n\n set number(value: number) {\n this.textContent = value.toString();\n }\n}\ndefine_element(ListNumberField);\n\nexport function number_field() {\n return new ListNumberField();\n}\n\nexport class ListNodeField<T extends Node> extends ListField {\n static element_name() {\n return \"nodefield\";\n }\n\n constructor(node: T) {\n super();\n this.appendChild(node);\n }\n\n set node(node: T) {\n this.replaceChildren(node);\n }\n\n get node() {\n return this.firstChild! as unknown as T;\n }\n}\ndefine_element(ListNodeField);\n\nexport function node_field<T extends Node>(node: T) {\n return new ListNodeField<T>(node);\n}\n","import { Base, define_element } from \"#base\";\nimport ctm, { ContextMenu } from \"#context-menu\";\nimport { some, type Option } from \"@chocbite/ts-lib/result\";\nimport { state, type State, type StateInferSub } from \"@chocbite/ts-lib/state\";\nimport state_ui from \"../state_ui\";\nimport { ListAddRow, type ListAddRowOptions } from \"./add_row\";\nimport { list_rows_error_update, ListError, type ListRowsError } from \"./error\";\nimport { list_align_apply, type ListField } from \"./field\";\nimport { ListKeyField, type ListKeyFieldOptions } from \"./key_field\";\nimport \"./row.scss\";\nimport type {\n ListParentRows,\n ListRoot,\n ListRowParent,\n ListRowTransformer,\n ListType,\n} from \"./types\";\n\nexport type ListSubRows<R> = () => R[] | State<R[]>;\n\nexport interface ListRowOptions<R, T extends {}, S extends boolean> {\n opened?: boolean;\n openable?: boolean | State<boolean>;\n key_field?: ListKeyFieldOptions;\n sub_rows?: S extends true ? ListSubRows<R> : never;\n add_row?: ListAddRowOptions;\n context_menu?: ContextMenu | (() => Option<ContextMenu>);\n values: T;\n}\n\nexport class ListRow<R, T extends {}, A extends ListType<R>, S extends boolean>\n extends Base\n implements ListRowParent<A>\n{\n static element_name() {\n return \"row\";\n }\n static element_name_space(): string {\n return \"list\";\n }\n #root: ListRoot<R, T, A, S>;\n #parent: ListRowParent<A>;\n #sub_rows?: ListSubRows<R>;\n readonly depth: number;\n #key_field?: ListKeyField<A>;\n #field_box: HTMLDivElement;\n #child_box: HTMLSpanElement;\n #add_row?: ListAddRow<R, T, A, S>;\n #fields: ListField[];\n #values!: T;\n /**Shown instead of the fields while the row is invalid */\n #invalid?: ListError;\n /**Shown instead of the sub rows while their state has an error */\n #error?: ListRowsError<A>;\n #open_pending = false;\n #sub_row_menu = false;\n #state_sub?: StateInferSub<State<R[]>>;\n state!: ListParentRows<A>;\n\n constructor(root: ListRoot<R, T, A, S>, parent: ListRowParent<A>, data: R) {\n super();\n this.#root = root;\n this.#parent = parent;\n this.depth = parent.depth + 1;\n this.style.setProperty(\"--i-\" + this.depth, \"var(--c)\");\n if (this.#root.sub_rows) {\n this.#key_field = new ListKeyField(this);\n if (this.#root.observer)\n this.#key_field.attach_to_intersect_observer(this.#root.observer);\n }\n this.#field_box = this.appendChild(document.createElement(\"div\"));\n this.#child_box = this.appendChild(document.createElement(\"span\"));\n //A right click on a sub row without its own menu reaches the child box before this row\n if (this.#root.sub_rows)\n this.#child_box.oncontextmenu = () => {\n this.#sub_row_menu = true;\n };\n this.#fields = this.#generate_fields();\n this.#show_cells(this.#fields);\n\n //Updates row data\n this.data = data;\n }\n\n #generate_fields(): ListField[] {\n return this.#root.columns_visible.map((key) => {\n const column = this.#root.columns.get(key)!;\n const field = column.field_gen();\n list_align_apply(field, column.align);\n if (this.#root.observer)\n field.attach_to_intersect_observer(this.#root.observer);\n return field;\n });\n }\n\n /**Shows the cells after the key field, which stays so an invalid row keeps its indent and arrow key navigation */\n #show_cells(cells: readonly HTMLElement[]) {\n if (this.#key_field)\n this.#field_box.replaceChildren(this.#key_field, ...cells);\n else this.#field_box.replaceChildren(...cells);\n }\n\n #apply_values() {\n this.#root.columns_visible.forEach((key, index) => {\n this.#root.columns\n .get(key)!\n .field_apply(this.#fields[index], this.#values[key]);\n });\n }\n\n /**Regenerates the fields of the row and its sub rows after the columns changed */\n columns_changed() {\n this.#fields = this.#generate_fields();\n //An invalid row has no values, the new fields are shown when it becomes valid\n if (!this.#invalid) {\n this.#show_cells(this.#fields);\n this.#apply_values();\n }\n for (let i = 0; i < this.#child_box.childElementCount; i++)\n (this.#child_box.children[i] as ListRow<R, T, A, S>).columns_changed();\n }\n\n // _____ _____ ______ _ _ _______\n // | __ \\ /\\ | __ \\| ____| \\ | |__ __|\n // | |__) / \\ | |__) | |__ | \\| | | |\n // | ___/ /\\ \\ | _ /| __| | . ` | | |\n // | | / ____ \\| | \\ \\| |____| |\\ | | |\n // |_| /_/ \\_\\_| \\_\\______|_| \\_| |_|\n\n select_adjacent(\n direction: \"next\" | \"previous\" | \"p_next\" | \"p_previous\" | \"last\",\n field: Option<number>,\n ) {\n if (!this.#key_field) return;\n //Open is not enough, an open row can show an error instead of sub rows\n const has_rows = this.#child_box.childElementCount > 0;\n if (direction === \"next\" || direction === \"p_next\") {\n if (direction === \"next\" && has_rows)\n (\n this.#child_box.firstElementChild! as ListRow<R, T, A, false>\n ).#key_field!.focus();\n else {\n const sibling = this.nextElementSibling;\n if (sibling instanceof ListRow) sibling.#key_field!.focus();\n else this.#parent.select_adjacent(\"p_next\", field);\n }\n } else if (direction === \"previous\") {\n const sibling = this.previousElementSibling;\n if (sibling instanceof ListRow) {\n if (sibling.open) sibling.select_adjacent(\"last\", field);\n else sibling.#key_field!.focus();\n } else this.#parent.select_adjacent(\"p_previous\", field);\n } else if (direction === \"p_previous\") this.#key_field.focus();\n else if (direction === \"last\") {\n if (has_rows) {\n (\n this.#child_box.lastElementChild as ListRow<R, T, A, S>\n ).select_adjacent(\"last\", field);\n } else this.#key_field.focus();\n }\n }\n\n // _____ _______\n // | __ \\ /\\|__ __|/\\\n // | | | | / \\ | | / \\\n // | | | |/ /\\ \\ | | / /\\ \\\n // | |__| / ____ \\| |/ ____ \\\n // |_____/_/ \\_\\_/_/ \\_\\\n\n set data(data: R) {\n const result = this.#root.transform(\n data,\n this,\n //Only the container gives top level rows, rows are only parents of sub rows\n this.#parent.state as Parameters<ListRowTransformer<R, T, A, S>>[2],\n );\n if (!result.ok) {\n this.#set_invalid(result.error);\n return;\n }\n const row_options = result.value;\n if (this.#invalid) {\n this.#invalid = undefined;\n this.#show_cells(this.#fields);\n }\n if (this.#key_field) this.#key_field.options = row_options.key_field;\n this.#sub_rows = row_options.sub_rows;\n\n this.add_row = row_options.add_row;\n\n this.#values = row_options.values;\n this.#apply_values();\n\n //Setup openable\n const was_open = this.open;\n if (state.is.state(row_options.openable)) {\n //Opening waits for the first value of the state, which is immediate when connected\n this.#open_pending = !was_open && Boolean(row_options.opened);\n this.attach_state_to_prop(\"openable\", row_options.openable, () =>\n some(false),\n );\n } else {\n this.#open_pending = false;\n this.detach_state_from_prop(\"openable\");\n this.openable = Boolean(row_options.openable);\n if (!was_open && row_options.opened) this.open = true;\n }\n\n //Refresh the sub rows of an open row\n if (was_open && this.open) {\n if (this.#sub_rows) this.rows = this.#sub_rows();\n else if (!row_options.opened) this.open = false;\n }\n\n //Setup context menu, blocked for right clicks bubbling up from sub rows\n ctm.detach(this);\n this.#sub_row_menu = false;\n if (row_options.context_menu)\n ctm.attach(this, row_options.context_menu, () => {\n const from_sub_row = this.#sub_row_menu;\n this.#sub_row_menu = false;\n return from_sub_row;\n });\n }\n\n /**Replaces the fields with the text and removes everything else the row options gave */\n #set_invalid(text: string) {\n if (this.#key_field) this.#key_field.options = undefined;\n this.#sub_rows = undefined;\n this.add_row = undefined;\n this.#open_pending = false;\n this.detach_state_from_prop(\"openable\");\n this.openable = false;\n ctm.detach(this);\n this.#sub_row_menu = false;\n if (!this.#invalid) {\n this.#invalid = new ListError();\n this.#show_cells([this.#invalid]);\n }\n this.#invalid.text = text;\n }\n\n set add_row(options: ListAddRowOptions | undefined) {\n if (!options && this.#add_row) {\n this.#add_row.remove();\n this.classList.remove(\"addrow\");\n this.#add_row = undefined;\n } else if (options) {\n if (!this.#add_row) {\n this.classList.add(\"addrow\");\n this.#add_row = this.appendChild(\n new ListAddRow<R, T, A, S>(this.#root, this),\n );\n }\n this.#add_row.options = options;\n }\n }\n\n // ____ _____ ______ _ _ _____ _ _ _____\n // / __ \\| __ \\| ____| \\ | |_ _| \\ | |/ ____|\n // | | | | |__) | |__ | \\| | | | | \\| | | __\n // | | | | ___/| __| | . ` | | | | . ` | | |_ |\n // | |__| | | | |____| |\\ |_| |_| |\\ | |__| |\n // \\____/|_| |______|_| \\_|_____|_| \\_|\\_____|\n\n set openable(value: boolean) {\n if (!value) this.open = false;\n if (this.#key_field) this.#key_field.openable = value;\n if (this.#open_pending) {\n this.#open_pending = false;\n if (value) this.open = true;\n }\n }\n get openable(): boolean {\n return this.#key_field?.openable ?? false;\n }\n\n set open(open: boolean) {\n if (!this.openable) return;\n if (open && this.#child_box.childElementCount === 0) {\n if (this.#sub_rows) this.rows = this.#sub_rows?.();\n } else if (!open && this.open) this.rows = [];\n }\n get open(): boolean {\n return this.classList.contains(\"open\");\n }\n\n // _____ ______ _______\n // | __ \\ / __ \\ \\ / / ____|\n // | |__) | | | \\ \\ /\\ / / (___\n // | _ /| | | |\\ \\/ \\/ / \\___ \\\n // | | \\ \\| |__| | \\ /\\ / ____) |\n // |_| \\_\\\\____/ \\/ \\/ |_____/\n\n get index(): number {\n return Array.prototype.indexOf.call(this.parentElement!.children, this);\n }\n\n amount_rows(rec: boolean = false): number {\n let count = this.#child_box.childElementCount;\n if (rec)\n for (let i = 0; i < this.#child_box.childElementCount; i++)\n count += (\n this.#child_box.children[i] as ListRow<R, T, A, S>\n ).amount_rows(true);\n return count;\n }\n\n set rows(rows: R[] | State<R[]>) {\n if (this.#state_sub) this.detach_state(this.#state_sub);\n this.#state_sub = undefined;\n //R is the item type of A\n this.state = rows as ListParentRows<A>;\n if (state.is.state(rows))\n this.#state_sub = this.attach_state(rows, (r) =>\n this.#update_rows(r.ok ? r.value : [], r.ok ? undefined : r.error),\n );\n else this.#update_rows(rows);\n }\n\n #update_rows(rows: readonly R[], error?: string) {\n this.#error = list_rows_error_update(\n this.#child_box,\n this.#error,\n error,\n this.#root.sub_rows,\n this,\n );\n this.classList.toggle(\"open\", rows.length > 0 || error !== undefined);\n state_ui.a.apply(this.#child_box, rows, {\n create: (row) => new ListRow<R, T, A, S>(this.#root, this, row),\n update: (element, row) => (element.data = row),\n });\n }\n}\ndefine_element(ListRow);\n","import { theme_init_variable_root } from \"#theme\";\nimport { GREY, ORANGE, RED } from \"@chocbite/ts-lib/colors\";\n\nconst theme_root = theme_init_variable_root(\n \"list\",\n \"UI List Elements\",\n \"Theme variables for UI list elements\",\n);\n\n// _____ ______ _____ ____ _ _ _ __ __\n// | __ \\| ____| /\\ | __ \\ / __ \\| \\ | | | \\ \\ / /\n// | |__) | |__ / \\ | | | | | | | | \\| | | \\ \\_/ /\n// | _ /| __| / /\\ \\ | | | | | | | | . ` | | \\ /\n// | | \\ \\| |____ / ____ \\| |__| | | |__| | |\\ | |____| |\n// |_| \\_\\______/_/ \\_\\_____/ \\____/|_| \\_|______|_|\nconst read_only = theme_root.make_sub_group(\n \"read\",\n \"Read Only\",\n \"Settings for list elements in read only mode\",\n);\nread_only.make_variable(\n \"filter\",\n \"Read Only Filter\",\n \"Filter applied to list elements in read only mode\",\n \"opacity(0.6)\",\n \"opacity(0.6)\",\n \"Filter\",\n undefined,\n);\n\n//#################################################################################3\n//#################################################################################3\n// _____ ____ _ ____ _____ _____\n// / ____/ __ \\| | / __ \\| __ \\ / ____|\n// | | | | | | | | | | | |__) | (___\n// | | | | | | | | | | | _ / \\___ \\\n// | |___| |__| | |___| |__| | | \\ \\ ____) |\n// \\_____\\____/|______\\____/|_| \\_\\_____/\nconst colors = theme_root.make_sub_group(\n \"colors\",\n \"Colors\",\n \"Colors used in all list elements\",\n);\n\n// _______ ________ _________ _____ ____ _ ____ _____ _____\n// |__ __| ____\\ \\ / /__ __| / ____/ __ \\| | / __ \\| __ \\ / ____|\n// | | | |__ \\ V / | | | | | | | | | | | | | |__) | (___\n// | | | __| > < | | | | | | | | | | | | | _ / \\___ \\\n// | | | |____ / . \\ | | | |___| |__| | |___| |__| | | \\ \\ ____) |\n// |_| |______/_/ \\_\\ |_| \\_____\\____/|______\\____/|_| \\_\\_____/\nconst colors_text = colors.make_sub_group(\n \"text\",\n \"Text Colors\",\n \"Text colors used in all list elements\",\n);\ncolors_text.make_variable(\n \"header\",\n \"Header Text Color\",\n \"Header text color in list elements\",\n GREY[\"900\"],\n GREY[\"50\"],\n \"Color\",\n undefined,\n);\ncolors_text.make_variable(\n \"field\",\n \"Field Text Color\",\n \"Text color of list field elements\",\n GREY[\"800\"],\n GREY[\"100\"],\n \"Color\",\n undefined,\n);\ncolors_text.make_variable(\n \"key_field\",\n \"Special Column Text Color\",\n \"Text color of special first column elements\",\n GREY[\"900\"],\n GREY[\"50\"],\n \"Color\",\n undefined,\n);\ncolors_text.make_variable(\n \"add\",\n \"Row Adder Text Color\",\n \"Text color of row adder button\",\n GREY[\"900\"],\n GREY[\"50\"],\n \"Color\",\n undefined,\n);\ncolors_text.make_variable(\n \"error\",\n \"Error Text Color\",\n \"Text color of list errors and invalid rows\",\n RED[\"800\"],\n RED[\"200\"],\n \"Color\",\n undefined,\n);\n\n// _____ _____ ____ _ _ _____ ____ _ ____ _____ _____\n// |_ _/ ____/ __ \\| \\ | | / ____/ __ \\| | / __ \\| __ \\ / ____|\n// | || | | | | | \\| | | | | | | | | | | | | |__) | (___\n// | || | | | | | . ` | | | | | | | | | | | | _ / \\___ \\\n// _| || |___| |__| | |\\ | | |___| |__| | |___| |__| | | \\ \\ ____) |\n// |_____\\_____\\____/|_| \\_| \\_____\\____/|______\\____/|_| \\_\\_____/\nconst colors_icon = colors.make_sub_group(\n \"icon\",\n \"Icon Colors\",\n \"Icon colors used in all form elements\",\n);\ncolors_icon.make_variable(\n \"sub_opener\",\n \"Sub Row Opener Icon Color\",\n \"Color of the sub row opener icon\",\n GREY[\"800\"],\n GREY[\"200\"],\n \"Color\",\n undefined,\n);\ncolors_icon.make_variable(\n \"key_icon\",\n \"Key Field Icon Color\",\n \"Color of the key field icon\",\n GREY[\"800\"],\n GREY[\"200\"],\n \"Color\",\n undefined,\n);\ncolors_icon.make_variable(\n \"add_icon\",\n \"Add Row Icon Color\",\n \"Color of the add row icon\",\n GREY[\"800\"],\n GREY[\"200\"],\n \"Color\",\n undefined,\n);\n\n// ____ _____ _ _______ _____ ____ _ _ _ _ _____ _____ ____ _ ____ _____ _____\n// | _ \\ /\\ / ____| |/ / ____| __ \\ / __ \\| | | | \\ | | __ \\ / ____/ __ \\| | / __ \\| __ \\ / ____|\n// | |_) | / \\ | | | ' / | __| |__) | | | | | | | \\| | | | | | | | | | | | | | | | |__) | (___\n// | _ < / /\\ \\| | | <| | |_ | _ /| | | | | | | . ` | | | | | | | | | | | | | | | _ / \\___ \\\n// | |_) / ____ \\ |____| . \\ |__| | | \\ \\| |__| | |__| | |\\ | |__| | | |___| |__| | |___| |__| | | \\ \\ ____) |\n// |____/_/ \\_\\_____|_|\\_\\_____|_| \\_\\\\____/ \\____/|_| \\_|_____/ \\_____\\____/|______\\____/|_| \\_\\_____/\nconst colors_background = colors.make_sub_group(\n \"background\",\n \"Background Colors\",\n \"Background colors used in all list elements\",\n);\ncolors_background.make_variable(\n \"row_even\",\n \"Even Row Background Color\",\n \"Color of even row element backgrounds\",\n GREY[\"200\"],\n GREY[\"800\"],\n \"Color\",\n undefined,\n);\ncolors_background.make_variable(\n \"row_odd\",\n \"Odd Row Background Color\",\n \"Color of odd row element backgrounds\",\n GREY[\"50\"],\n GREY[\"900\"],\n \"Color\",\n undefined,\n);\ncolors_background.make_variable(\n \"row_hover\",\n \"Hover Row Background Color\",\n \"Color of row element backgrounds when hovering\",\n GREY[\"300\"],\n GREY[\"700\"],\n \"Color\",\n undefined,\n);\n\n// ____ ____ _____ _____ ______ _____ _____ ____ _ ____ _____ _____\n// | _ \\ / __ \\| __ \\| __ \\| ____| __ \\ / ____/ __ \\| | / __ \\| __ \\ / ____|\n// | |_) | | | | |__) | | | | |__ | |__) | | | | | | | | | | | | |__) | (___\n// | _ <| | | | _ /| | | | __| | _ / | | | | | | | | | | | _ / \\___ \\\n// | |_) | |__| | | \\ \\| |__| | |____| | \\ \\ | |___| |__| | |___| |__| | | \\ \\ ____) |\n// |____/ \\____/|_| \\_\\_____/|______|_| \\_\\ \\_____\\____/|______\\____/|_| \\_\\_____/\nconst colors_border = colors.make_sub_group(\n \"border\",\n \"Border Colors\",\n \"Border colors used in all list elements\",\n);\ncolors_border.make_variable(\n \"header\",\n \"Header Border Color\",\n \"Color of borders under header\",\n GREY[\"600\"],\n GREY[\"400\"],\n \"Color\",\n undefined,\n);\ncolors_border.make_variable(\n \"row\",\n \"Row Border Color\",\n \"Color of borders between rows\",\n GREY[\"400\"],\n GREY[\"600\"],\n \"Color\",\n undefined,\n);\ncolors_border.make_variable(\n \"column\",\n \"Column Border Color\",\n \"Color of border between columns\",\n GREY[\"500\"],\n GREY[\"500\"],\n \"Color\",\n undefined,\n);\n\n// ______ ____ _____ _ _ _____\n// | ____/ __ \\ / ____| | | |/ ____|\n// | |__ | | | | | | | | | (___\n// | __|| | | | | | | | |\\___ \\\n// | | | |__| | |____| |__| |____) |\n// |_| \\____/ \\_____|\\____/|_____/\nconst colors_focus = colors.make_sub_group(\n \"focus\",\n \"Focus Colors\",\n \"Focus colors used in all list elements\",\n);\ncolors_focus.make_variable(\n \"normal\",\n \"Focus Color\",\n \"Color of focussed list element\",\n ORANGE[\"600\"],\n ORANGE[\"300\"],\n \"Color\",\n undefined,\n);\n\n//#################################################################################3\n//#################################################################################3\n// _____ _____ ____________ _____\n// / ____|_ _|___ / ____|/ ____|\n// | (___ | | / /| |__ | (___\n// \\___ \\ | | / / | __| \\___ \\\n// ____) |_| |_ / /__| |____ ____) |\n// |_____/|_____/_____|______|_____/\nconst sizes = theme_root.make_sub_group(\n \"size\",\n \"Size\",\n \"Sizes used in all list elements\",\n);\n\nsizes.make_variable(\n \"row_min\",\n \"Row Minimum Height\",\n \"Minimum height for list rows\",\n \"1.4rem\",\n \"1.4rem\",\n \"Length\",\n { min: 0.1, max: 10 },\n);\n\nsizes.make_variable(\n \"touch_row_min\",\n \"Touch Row Minimum Height\",\n \"Minimum height for list rows on touch devices\",\n \"2.6rem\",\n \"2.6rem\",\n \"Length\",\n { min: 0.1, max: 10 },\n);\n\nsizes.make_variable(\n \"add_min\",\n \"Add Row Minimum Height\",\n \"Minimum height for add row button\",\n \"1rem\",\n \"1rem\",\n \"Length\",\n { min: 0.1, max: 10 },\n);\n\nsizes.make_variable(\n \"touch_add_min\",\n \"Touch Add Row Minimum Height\",\n \"Minimum height for add row button on touch devices\",\n \"2rem\",\n \"2rem\",\n \"Length\",\n { min: 0.1, max: 10 },\n);\n\n//#################################################################################3\n//#################################################################################3\n// _ _ _____ __ __ _______ _____ ____ _ _\n// /\\ | \\ | |_ _| \\/ | /\\|__ __|_ _/ __ \\| \\ | |\n// / \\ | \\| | | | | \\ / | / \\ | | | || | | | \\| |\n// / /\\ \\ | . ` | | | | |\\/| | / /\\ \\ | | | || | | | . ` |\n// / ____ \\| |\\ |_| |_| | | |/ ____ \\| | _| || |__| | |\\ |\n// /_/ \\_\\_| \\_|_____|_| |_/_/ \\_\\_| |_____\\____/|_| \\_|\nconst animation = theme_root.make_sub_group(\n \"animation\",\n \"Animation\",\n \"Animation settings used in all list elements\",\n);\n\nanimation.make_variable(\n \"transitionType\",\n \"Transition Type\",\n \"Type of transition used in list element animations\",\n \"ease-in-out\",\n \"ease-in-out\",\n \"TransitionType\",\n undefined,\n);\n\nanimation.make_variable(\n \"transitionDuration\",\n \"Transition Duration\",\n \"Duration of transitions used in list element animations\",\n \"200ms\",\n \"200ms\",\n \"Time\",\n { min: 0, max: 5000 },\n);\n\n//#################################################################################3\n//#################################################################################3\n// ______ ____ _ _ _______\n// | ____/ __ \\| \\ | |__ __|\n// | |__ | | | | \\| | | |\n// | __|| | | | . ` | | |\n// | | | |__| | |\\ | | |\n// |_| \\____/|_| \\_| |_|\nconst font = theme_root.make_sub_group(\n \"font\",\n \"Font\",\n \"Font settings used in all list elements\",\n);\n\nfont.make_variable(\n \"size\",\n \"Font Size\",\n \"Default font size used in all list elements\",\n \"1rem\",\n \"1rem\",\n \"Length\",\n { min: 0.1, max: 10 },\n);\n\nfont.make_variable(\n \"touchSize\",\n \"Touch Font Size\",\n \"Font size used in all list elements for touch devices\",\n \"1.2rem\",\n \"1.2rem\",\n \"Length\",\n { min: 0.1, max: 10 },\n);\n","import { Base, define_element, type BaseIntersectObserver } from \"#base\";\nimport { px_to_rem } from \"#theme\";\nimport { state, type State, type StateInferSub } from \"@chocbite/ts-lib/state\";\nimport state_ui from \"../state_ui\";\nimport { ListAddRow, type ListAddRowOptions } from \"./add_row\";\nimport \"./container.scss\";\nimport { list_rows_error_update, type ListRowsError } from \"./error\";\nimport { list_align_apply, text_field } from \"./field\";\nimport { ListRow } from \"./row\";\nimport \"./shared\";\nimport type {\n ListColumnOptions,\n ListRoot,\n ListRowParent,\n ListRowTransformer,\n ListType,\n ListTypeExtract,\n} from \"./types.ts\";\n\nclass HeaderField extends Base {\n static element_name() {\n return \"headerfield\";\n }\n static element_name_space(): string {\n return \"list\";\n }\n\n #box = this.appendChild(document.createElement(\"div\"));\n #text = this.#box.appendChild(document.createElement(\"span\"));\n #sizer?: HTMLDivElement;\n\n constructor(text?: string) {\n super();\n if (text) this.text = text;\n }\n\n set text(value: string) {\n this.#text.textContent = value;\n }\n\n sizable(sizeable: boolean, sizer: (width: number | undefined) => void) {\n if (sizeable) {\n this.#sizer = this.#box.appendChild(document.createElement(\"div\"));\n let double_timeout: number;\n this.#sizer.onpointerdown = (e) => {\n e.preventDefault();\n if (double_timeout) {\n sizer(undefined);\n return;\n }\n double_timeout = window.setTimeout(() => {\n double_timeout = 0;\n }, 300);\n this.setPointerCapture(e.pointerId);\n const start_x = e.pageX;\n const start_width = this.#box.offsetWidth;\n this.onpointermove = (ev: PointerEvent) => {\n sizer(px_to_rem(start_width + (ev.pageX - start_x)));\n };\n this.onpointerup = () => {\n this.releasePointerCapture(e.pointerId);\n this.onpointermove = null;\n this.onpointerup = null;\n };\n };\n } else if (this.#sizer) {\n this.#sizer.remove();\n this.#sizer = undefined;\n }\n }\n}\ndefine_element(HeaderField);\n\nclass HeaderRow<\n R,\n T extends {},\n A extends ListType<R>,\n S extends boolean,\n> extends Base {\n static element_name() {\n return \"headerrow\";\n }\n static element_name_space(): string {\n return \"list\";\n }\n\n set fields(fields: HeaderField[]) {\n if (this.#root.sub_rows) this.replaceChildren(text_field(), ...fields);\n else this.replaceChildren(...fields);\n }\n\n #root: ListRoot<R, T, A, S>;\n\n constructor(root: ListRoot<R, T, A, S>) {\n super();\n this.#root = root;\n }\n}\ndefine_element(HeaderRow);\n\ninterface ContainerOptions<S extends boolean = false> {\n /**Should header row be omitted */\n headless?: boolean;\n /**Can rows have sub rows */\n sub_rows?: S;\n /**Options for an add row button */\n add_row?: ListAddRowOptions;\n /**If list should use a container to give fields the option of attach/detach to states when visible */\n observer?: BaseIntersectObserver;\n}\n\nclass Container<\n A extends ListType<any>,\n T extends { [key: string]: ListColumnOptions<any, any> },\n S extends boolean = false,\n R = ListTypeExtract<A>,\n> extends Base {\n static element_name() {\n return \"container\";\n }\n static element_name_space() {\n return \"list\";\n }\n\n #root: ListRoot<R, T, A, S>;\n #parent: ListRowParent<A>;\n #box = this.appendChild(document.createElement(\"div\"));\n #header?: HeaderRow<R, T, A, S>;\n #child_box: HTMLDivElement;\n #error?: ListRowsError<A>;\n #add_row?: ListAddRow<R, T, A, S>;\n #state_sub?: StateInferSub<State<R[]>>;\n\n constructor(\n columns: { [K in keyof T]: ListColumnOptions<T[K], any> },\n transform: ListRowTransformer<R, T, A, S>,\n rows: A,\n options?: ContainerOptions<S>,\n ) {\n super();\n this.#root = {\n sub_rows: options?.sub_rows ?? (false as S),\n columns: new Map(),\n columns_visible: [],\n transform,\n observer: options?.observer,\n };\n this.#parent = {\n depth: -1,\n open: false,\n select_adjacent() {},\n state: rows,\n };\n\n if (!options?.headless)\n this.#header = this.#box.appendChild(new HeaderRow(this.#root));\n this.#child_box = this.#box.appendChild(document.createElement(\"div\"));\n if (options?.sub_rows) this.#box.classList.add(\"sub-rows\");\n this.add_row = options?.add_row;\n\n this.columns = columns;\n this.rows = rows;\n }\n\n set columns(columns: { [K in keyof T]: ListColumnOptions<T[K], any> }) {\n this.#root.columns.clear();\n const order = new Map<keyof T, number>();\n let index = 0;\n for (const key in columns) {\n //Copied, so resizing does not write into the callers options\n this.#root.columns.set(key, { ...columns[key as keyof T] });\n order.set(key, columns[key].order ?? index);\n index++;\n }\n this.#root.columns_visible = [...order.keys()].sort(\n (a, b) => order.get(a)! - order.get(b)!,\n );\n\n if (this.#header)\n this.#header.fields = this.#root.columns_visible.map((key) => {\n const column = this.#root.columns.get(key)!;\n const header = new HeaderField(column.title);\n list_align_apply(header, column.align);\n header.sizable(typeof column.fixed_width === \"undefined\", (width) => {\n column.init_width = width;\n this.#update_column_widths();\n });\n return header;\n });\n this.#update_column_widths();\n\n for (let i = 0; i < this.#child_box.childElementCount; i++)\n (this.#child_box.children[i] as ListRow<R, T, A, S>).columns_changed();\n }\n\n #update_column_widths() {\n const widths: string[] = this.#root.columns_visible.map((key) => {\n const col = this.#root.columns.get(key)!;\n const width = col.fixed_width ?? col.init_width;\n if (width) {\n if (width === \"min\") return \"min-content\";\n else if (width === \"max\") return \"max-content\";\n return `${Math.max(width, 1)}rem`;\n }\n return \"auto\";\n });\n if (this.#root.sub_rows) widths.unshift(\"min-content\");\n this.#box.style.gridTemplateColumns = widths.join(\" \");\n }\n\n set add_row(options: ListAddRowOptions | undefined) {\n if (!options && this.#add_row) {\n this.#add_row.remove();\n this.#box.classList.remove(\"addrow\");\n this.#add_row = undefined;\n } else if (options) {\n if (!this.#add_row) {\n this.#box.classList.add(\"addrow\");\n this.#add_row = this.#box.appendChild(\n new ListAddRow<R, T, A, S>(this.#root, this.#parent),\n );\n }\n this.#add_row.options = options;\n }\n }\n\n // _____ ______ _______\n // | __ \\ / __ \\ \\ / / ____|\n // | |__) | | | \\ \\ /\\ / / (___\n // | _ /| | | |\\ \\/ \\/ / \\___ \\\n // | | \\ \\| |__| | \\ /\\ / ____) |\n // |_| \\_\\\\____/ \\/ \\/ |_____/\n\n amount_rows(rec: boolean = false): number {\n let count = this.#child_box.childElementCount;\n if (rec)\n for (let i = 0; i < this.#child_box.childElementCount; i++)\n count += (\n this.#child_box.children[i] as ListRow<R, T, A, S>\n ).amount_rows(true);\n return count;\n }\n\n set rows(rows: R[] | State<R[]>) {\n if (this.#state_sub) this.detach_state(this.#state_sub);\n this.#state_sub = undefined;\n this.#parent.state = rows as A;\n if (state.is.state(rows))\n this.#state_sub = this.attach_state(rows, (r) =>\n this.#update_rows(r.ok ? r.value : [], r.ok ? undefined : r.error),\n );\n else this.#update_rows(rows);\n }\n\n #update_rows(rows: readonly R[], error?: string) {\n this.#error = list_rows_error_update(\n this.#child_box,\n this.#error,\n error,\n this.#root.sub_rows,\n this.#parent,\n );\n state_ui.a.apply(this.#child_box, rows, {\n create: (row) => new ListRow<R, T, A, S>(this.#root, this.#parent, row),\n update: (element, row) => (element.data = row),\n });\n }\n}\ndefine_element(Container);\n\nexport function container<\n A extends ListType<any>,\n T extends {},\n S extends boolean = false,\n R = ListTypeExtract<A>,\n>(\n columns: { [K in keyof T]: ListColumnOptions<T[K], any> },\n transform: ListRowTransformer<R, NoInfer<T>, A, S>,\n rows: A,\n options?: ContainerOptions<S>,\n) {\n return new Container<A, T, S, R>(columns, transform, rows, options);\n}\n","import type { BaseIntersectObserver } from \"#base\";\nimport { type Option, type Result } from \"@chocbite/ts-lib/result\";\nimport type { State } from \"@chocbite/ts-lib/state\";\nimport list from \".\";\nimport type { ListField, ListTextField } from \"./field\";\nimport type { ListRow, ListRowOptions } from \"./row\";\n\nexport type ListType<R> = R[] | State<R[]>;\n\nexport type ListTypeExtract<A extends ListType<any>> = A extends (infer U)[]\n ? U\n : A extends State<(infer U)[]>\n ? U\n : never;\n\n/**Rows of a row parent, the top level rows or sub rows, which can be an array or a state regardless of the top level rows */\nexport type ListParentRows<A extends ListType<any>> =\n | A\n | ListType<ListTypeExtract<A>>;\n\nexport const ListDataType = {\n number: \"number\",\n string: \"string\",\n bool: \"bool\",\n} as const;\nexport type ListDataType = (typeof ListDataType)[keyof typeof ListDataType];\n\nexport type ListColumnAlign = \"left\" | \"center\" | \"right\";\n\nexport interface ListColumnOptions<V, C extends ListField> {\n /**Initial width of the column in rem, auto when undefined*/\n init_width?: number;\n /**If the column has a fixed width in rem, overrides init_width and disables resizing*/\n fixed_width?: number | \"min\" | \"max\";\n /**Initial order of the column, lower numbers appear first, will order by column object if undefined\n * A column without order uses its position in the column object as order*/\n order?: number;\n /**Whether the column is reorderable by the user*/\n reorderable?: boolean;\n /**Data type of the column, used for sorting, will attempt auto detect if undefined*/\n type?: ListDataType;\n /**Horizontal alignment of the title and the fields, center when undefined\n * Text, number and node fields follow it, more complex fields like form fields do not */\n align?: ListColumnAlign;\n /**Column title*/\n title: string;\n /**Generates the field element, only called during row or column creation */\n field_gen(): C;\n /**Applies the value to the field */\n field_apply(field: C, value: V): void;\n}\n\n/**Helper to create a column object */\nexport function column<V, C extends ListField>(\n options: ListColumnOptions<V, C>,\n): ListColumnOptions<V, C> {\n return options;\n}\n\n/**Special helper to create a string value column */\nexport function column_string(\n /**Column title*/\n title: string,\n options?: { align?: ListColumnAlign },\n): ListColumnOptions<string, ListTextField> {\n return {\n title,\n align: options?.align,\n field_gen: () => list.text_field(),\n field_apply: (field, value) => (field.text = value),\n };\n}\n\n/**Transforms the data of a row into row options\n * Returning an error makes the row invalid, the error text then replaces the fields of the row\n * An invalid row is for failures with no other options, so it has no sub rows, add row or context menu */\nexport type ListRowTransformer<\n R,\n T extends {},\n A extends ListType<any>,\n S extends boolean,\n> = (\n /**Data of the row */\n data: R,\n /**The row the options are for */\n row: ListRow<R, T, A, S>,\n /**Rows the data is from, sub rows can come from an array or a state regardless of the top level rows */\n state: S extends true ? A | ListType<R> : A,\n) => Result<ListRowOptions<R, T, S>, string>;\n\nexport interface ListRoot<\n R,\n T extends {},\n A extends ListType<any>,\n S extends boolean,\n> {\n /**Sub rows */\n readonly sub_rows: S;\n /**Columns options mapped by column key */\n readonly columns: Map<keyof T, ListColumnOptions<T[keyof T], ListField>>;\n /**Order of visible columns by column key */\n columns_visible: (keyof T)[];\n /**Function to transform a row data into row options */\n transform: ListRowTransformer<R, T, A, S>;\n /**Observer for the container if observer is active */\n observer?: BaseIntersectObserver;\n}\n\nexport interface ListRowParent<A extends ListType<any>> {\n /**Sub row depth */\n readonly depth: number;\n /**Whether the row is open to show sub rows */\n open: boolean;\n /**Selects the adjacent row in the given direction */\n select_adjacent(\n direction: \"next\" | \"previous\" | \"p_next\" | \"p_previous\" | \"last\",\n field: Option<number>,\n ): void;\n /**Rows of the parent, the rows of the container or the sub rows of a row */\n state: ListParentRows<A>;\n}\n","import { container } from \"./container\";\nimport { node_field, number_field, text_field } from \"./field\";\nimport { column, column_string } from \"./types\";\n\nexport const list = {\n column,\n column_string,\n container,\n text_field,\n number_field,\n node_field,\n};\n\nexport { ListField } from \"./field\";\n\nexport default list;\n"],"mappings":";;;;;;;;;;AAYA,IAAa,eAAb,cAA2D,KAAK;CAC9D,OAAO,eAAe;EACpB,OAAO;CACT;CACA,OAAO,qBAAqB;EAC1B,OAAO;CACT;CAEA;CACA;CACA;CAEA,YAAY,QAA0B;EACpC,MAAM;EACN,KAAK,WAAW;EAChB,KAAK,aAAa,MAAM;GACtB,IAAI,EAAE,QAAQ,WAAW,EAAE,QAAQ,KAAK,OAAO,OAAO,CAAC,OAAO;QACzD,IAAI,EAA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7B;CAEA,aAAa,MAAoB,OAAgB;EAC/C,KAAK,SAAS,uBACZ,KAAK,YACL,KAAK,QACL,OACA,KAAK,MAAM,UACX,IACF;EACA,KAAK,UAAU,OAAO,QAAQ,KAAK,SAAS,KAAK,UAAU,KAAA,CAAS;EACpE,SAAS,EAAE,MAAM,KAAK,YAAY,MAAM;GACtC,SAAS,QAAQ,IAAI,QAAoB,KAAK,OAAO,MAAM,GAAG;GAC9D,SAAS,SAAS,QAAS,QAAQ,OAAO;EAC5C,CAAC;CACH;AACF;AACA,eAAe,OAAO;;AC5UtB,MAAM,aAAa,yBACjB,QACA,oBACA,sCACF;AAQkB,WAAW,eAC3B,QACA,aACA,8CAEM,CAAC,CAAC,cACR,UACA,oBACA,qDACA,gBACA,gBACA,UACA,KAAA,CACF;AAUA,MAAM,SAAS,WAAW,eACxB,UACA,UACA,kCACF;AAQA,MAAM,cAAc,OAAO,eACzB,QACA,eACA,uCACF;AACA,YAAY,cACV,UACA,qBACA,sCACA,KAAK,QACL,KAAK,OACL,SACA,KAAA,CACF;AACA,YAAY,cACV,SACA,oBACA,qCACA,KAAK,QACL,KAAK,QACL,SACA,KAAA,CACF;AACA,YAAY,cACV,aACA,6BACA,+CACA,KAAK,QACL,KAAK,OACL,SACA,KAAA,CACF;AACA,YAAY,cACV,OACA,wBACA,kCACA,KAAK,QACL,KAAK,OACL,SACA,KAAA,CACF;AACA,YAAY,cACV,SACA,oBACA,8CACA,IAAI,QACJ,IAAI,QACJ,SACA,KAAA,CACF;AAQA,MAAM,cAAc,OAAO,eACzB,QACA,eACA,uCACF;AACA,YAAY,cACV,cACA,6BACA,oCACA,KAAK,QACL,KAAK,QACL,SACA,KAAA,CACF;AACA,YAAY,cACV,YACA,wBACA,+BACA,KAAK,QACL,KAAK,QACL,SACA,KAAA,CACF;AACA,YAAY,cACV,YACA,sBACA,6BACA,KAAK,QACL,KAAK,QACL,SACA,KAAA,CACF;AAQA,MAAM,oBAAoB,OAAO,eAC/B,cACA,qBACA,6CACF;AACA,kBAAkB,cAChB,YACA,6BACA,yCACA,KAAK,QACL,KAAK,QACL,SACA,KAAA,CACF;AACA,kBAAkB,cAChB,WACA,4BACA,wCACA,KAAK,OACL,KAAK,QACL,SACA,KAAA,CACF;AACA,kBAAkB,cAChB,aACA,8BACA,kDACA,KAAK,QACL,KAAK,QACL,SACA,KAAA,CACF;AAQA,MAAM,gBAAgB,OAAO,eAC3B,UACA,iBACA,yCACF;AACA,cAAc,cACZ,UACA,uBACA,iCACA,KAAK,QACL,KAAK,QACL,SACA,KAAA,CACF;AACA,cAAc,cACZ,OACA,oBACA,iCACA,KAAK,QACL,KAAK,QACL,SACA,KAAA,CACF;AACA,cAAc,cACZ,UACA,uBACA,mCACA,KAAK,QACL,KAAK,QACL,SACA,KAAA,CACF;AAQqB,OAAO,eAC1B,SACA,gBACA,wCAES,CAAC,CAAC,cACX,UACA,eACA,kCACA,OAAO,QACP,OAAO,QACP,SACA,KAAA,CACF;AAUA,MAAM,QAAQ,WAAW,eACvB,QACA,QACA,iCACF;AAEA,MAAM,cACJ,WACA,sBACA,gCACA,UACA,UACA,UACA;CAAE,KAAK;CAAK,KAAK;AAAG,CACtB;AAEA,MAAM,cACJ,iBACA,4BACA,iDACA,UACA,UACA,UACA;CAAE,KAAK;CAAK,KAAK;AAAG,CACtB;AAEA,MAAM,cACJ,WACA,0BACA,qCACA,QACA,QACA,UACA;CAAE,KAAK;CAAK,KAAK;AAAG,CACtB;AAEA,MAAM,cACJ,iBACA,gCACA,sDACA,QACA,QACA,UACA;CAAE,KAAK;CAAK,KAAK;AAAG,CACtB;AAUA,MAAM,YAAY,WAAW,eAC3B,aACA,aACA,8CACF;AAEA,UAAU,cACR,kBACA,mBACA,sDACA,eACA,eACA,kBACA,KAAA,CACF;AAEA,UAAU,cACR,sBACA,uBACA,2DACA,SACA,SACA,QACA;CAAE,KAAK;CAAG,KAAK;AAAK,CACtB;AAUA,MAAM,OAAO,WAAW,eACtB,QACA,QACA,yCACF;AA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A;CACA;CACA;CACA;CACA;AACF"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@chocbite/ts-lib-ui",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.6",
|
|
4
4
|
"description": "Browser UI TypeScript libraries, builds on @chocbite/ts-lib",
|
|
5
5
|
"author": "chocolateandmilkwin",
|
|
6
6
|
"license": "MIT",
|
|
@@ -80,6 +80,11 @@
|
|
|
80
80
|
"import": "./svg/index.mjs",
|
|
81
81
|
"style": "./style.css"
|
|
82
82
|
},
|
|
83
|
+
"./test": {
|
|
84
|
+
"types": "./test/index.d.mts",
|
|
85
|
+
"import": "./test/index.mjs",
|
|
86
|
+
"style": "./style.css"
|
|
87
|
+
},
|
|
83
88
|
"./theme": {
|
|
84
89
|
"types": "./theme/index.d.mts",
|
|
85
90
|
"import": "./theme/index.mjs",
|
|
@@ -89,7 +94,7 @@
|
|
|
89
94
|
"./theme/mixins": "./theme/mixins.scss"
|
|
90
95
|
},
|
|
91
96
|
"dependencies": {
|
|
92
|
-
"@chocbite/ts-lib": "^1.0.
|
|
97
|
+
"@chocbite/ts-lib": "^1.0.6"
|
|
93
98
|
},
|
|
94
99
|
"publishConfig": {
|
|
95
100
|
"access": "public"
|
package/spinner/index.d.mts
CHANGED
package/spinner/index.mjs
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import "../style.css";
|
|
2
2
|
import { Base, define_element } from "../base/index.mjs";
|
|
3
3
|
import { t as svg } from "../svg-1bp-yIPC.mjs";
|
|
4
|
-
import { i as theme_init_variable_root } from "../theme-
|
|
4
|
+
import { i as theme_init_variable_root } from "../theme-DgVtLDzP.mjs";
|
|
5
5
|
import { GREY } from "@chocbite/ts-lib/colors";
|
|
6
6
|
// src/spinner/index.ts
|
|
7
7
|
theme_init_variable_root("spinners", "Spinner", "Spinner used as a placeholder for data with and unknown arrival time").make_variable("color", "Dot color", "Color of dots in spinner", GREY["700"], GREY["300"], "Color", void 0);
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import "./style.css";
|
|
2
2
|
import state from "@chocbite/ts-lib/state";
|
|
3
|
-
// src/
|
|
3
|
+
// src/state_ui/array.ts
|
|
4
4
|
/**Applies an array to the child nodes of a parent, one node per value.
|
|
5
5
|
* Arrays from array states carry what changed, so only the changed nodes are touched,
|
|
6
6
|
* a plain array is applied as a whole, reusing existing nodes when update is given.
|
|
@@ -74,7 +74,7 @@ const ARRAY_UI = {
|
|
|
74
74
|
* @param array new value of the array
|
|
75
75
|
* @param handlers make, update and remove the nodes*/
|
|
76
76
|
apply };
|
|
77
|
-
// src/
|
|
77
|
+
// src/state_ui/index.ts
|
|
78
78
|
/**Shows states of @chocbite/ts-lib/state in the document*/
|
|
79
79
|
const state_ui = {
|
|
80
80
|
/**Array states, applies arrays to child nodes*/
|
|
@@ -84,4 +84,4 @@ const state_ui = {
|
|
|
84
84
|
};
|
|
85
85
|
export { state_ui as t };
|
|
86
86
|
|
|
87
|
-
//# sourceMappingURL=
|
|
87
|
+
//# sourceMappingURL=state_ui-Bm3TeKNL.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"state_ui-Bm3TeKNL.mjs","names":[],"sources":["../src/state_ui/array.ts","../src/state_ui/index.ts"],"sourcesContent":["import state from \"@chocbite/ts-lib/state\";\n\n/**How the nodes for the values of an array are made, updated and removed*/\nexport interface StateUIArrayApplyHandlers<T, N extends ChildNode> {\n /**Gives the node for a value*/\n create: (value: T) => N;\n /**Updates a node to a new value, when given nodes are reused, otherwise nodes of changed values are replaced*/\n update?: (node: N, value: T) => void;\n /**Called for every node that is removed or replaced*/\n destroy?: (node: N) => void;\n}\n\n/**Applies an array to the child nodes of a parent, one node per value.\n * Arrays from array states carry what changed, so only the changed nodes are touched,\n * a plain array is applied as a whole, reusing existing nodes when update is given.\n * @param parent node holding the nodes for the array, it must contain nothing else\n * @param array new value of the array\n * @param handlers make, update and remove the nodes*/\nfunction apply<T, N extends ChildNode>(\n parent: ParentNode,\n array: readonly T[],\n handlers: StateUIArrayApplyHandlers<T, N>,\n): void {\n const { create, update, destroy } = handlers;\n //Live list, it follows every change made below\n const nodes = parent.childNodes as NodeListOf<N>;\n const remove = (node: N) => {\n destroy?.(node);\n node.remove();\n };\n for (const change of state.a.read(array)) {\n switch (change.type) {\n case \"fresh\": {\n if (update) {\n const reused = Math.min(nodes.length, change.items.length);\n for (let i = 0; i < reused; i++) update(nodes[i], change.items[i]);\n while (nodes.length > change.items.length)\n remove(nodes[nodes.length - 1]);\n parent.append(...change.items.slice(reused).map((v) => create(v)));\n } else {\n if (destroy) for (const node of [...nodes]) destroy(node);\n parent.replaceChildren(...change.items.map((v) => create(v)));\n }\n break;\n }\n case \"added\": {\n const created = change.items.map((v) => create(v));\n const next = nodes[change.index];\n if (next) next.before(...created);\n else parent.append(...created);\n break;\n }\n case \"removed\":\n for (let i = 0; i < change.items.length; i++) {\n const node = nodes[change.index];\n if (node) remove(node);\n }\n break;\n case \"changed\":\n for (let i = 0; i < change.items.length; i++) {\n const node = nodes[change.index + i];\n if (!node) continue;\n if (update) update(node, change.items[i]);\n else {\n destroy?.(node);\n node.replaceWith(create(change.items[i]));\n }\n }\n break;\n case \"moved\": {\n const moved: N[] = [];\n //Every removal moves the next node to from_index\n for (let i = 0; i < change.items.length; i++) {\n const node = nodes[change.from_index];\n if (!node) break;\n moved.push(node);\n node.remove();\n }\n const next = nodes[change.to_index];\n if (next) next.before(...moved);\n else parent.append(...moved);\n break;\n }\n }\n }\n}\n\n/**Array states shown in the document*/\nexport const ARRAY_UI = {\n /**Applies an array to the child nodes of a parent, one node per value.\n * Arrays from array states carry what changed, so only the changed nodes are touched,\n * a plain array is applied as a whole, reusing existing nodes when update is given.\n * @param parent node holding the nodes for the array, it must contain nothing else\n * @param array new value of the array\n * @param handlers make, update and remove the nodes*/\n apply,\n};\n","import { ARRAY_UI } from \"./array\";\n\n/**Shows states of @chocbite/ts-lib/state in the document*/\nexport const state_ui = {\n //The \"as typeof\" casts make the declaration output reference the helper objects instead of inlining\n //their types, inlining would drop the doc comments on their members\n /* eslint-disable @typescript-eslint/no-unnecessary-type-assertion */\n /**Array states, applies arrays to child nodes*/\n a: ARRAY_UI as typeof ARRAY_UI,\n /**Array states, applies arrays to child nodes*/\n array: ARRAY_UI as typeof ARRAY_UI,\n /* eslint-enable @typescript-eslint/no-unnecessary-type-assertion */\n};\nexport default state_ui;\n\nexport type { StateUIArrayApplyHandlers } from \"./array\";\n"],"mappings":";;;;;;;;;AAkBA,SAAS,MACP,QACA,OACA,UACM;CACN,MAAM,EAAE,QAAQ,QAAQ,YAAY;CAEpC,MAAM,QAAQ,OAAO;CACrB,MAAM,UAAU,SAAY;EAC1B,UAAU,IAAI;EACd,KAAK,OAAO;CACd;CACA,KAAK,MAAM,UAAU,MAAM,EAAE,KAAK,KAAK,GACrC,QAAQ,OAAO,MAAf;EACE,KAAK;GACH,IAAI,QAAQ;IACV,MAAM,SAAS,KAAK,IAAI,MAAM,QAAQ,OAAO,MAAM,MAAM;IACzD,KAAK,IAAI,IAAI,GAAG,IAAI,QAAQ,KAAK,OAAO,MAAM,IAAI,OAAO,MAAM,EAAE;IACjE,OAAO,MAAM,SAAS,OAAO,MAAM,QACjC,OAAO,MAAM,MAAM,SAAS,EAAE;IAChC,OAAO,OAAO,GAAG,OAAO,MAAM,MAAM,MAAM,CAAC,CAAC,KAAK,MAAM,OAAO,CAAC,CAAC,CAAC;GACnE,OAAO;IACL,IAAI,SAAS,KAAK,MAAM,QAAQ,CAAC,GAAG,KAAK,GAAG,QAAQ,IAAI;IACxD,OAAO,gBAAgB,GAAG,OAAO,MAAM,KAAK,MAAM,OAAO,CAAC,CAAC,CAAC;GAC9D;GACA;EAEF,KAAK,SAAS;GACZ,MAAM,UAAU,OAAO,MAAM,KAAK,MAAM,OAAO,CAAC,CAAC;GACjD,MAAM,OAAO,MAAM,OAAO;GAC1B,IAAI,MAAM,KAA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