@jsweb/ui 1.2.8 → 1.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.github/workflows/npm-publish.yml +19 -0
- package/.prettierignore +3 -0
- package/.prettierrc +7 -0
- package/LICENSE +21 -21
- package/PROJECT.md +106 -0
- package/README.md +137 -18
- package/dist/LICENSE +21 -0
- package/dist/README.md +227 -0
- package/dist/index.es.js +2 -0
- package/dist/index.es.js.map +1 -0
- package/dist/index.umd.js +2 -0
- package/dist/index.umd.js.map +1 -0
- package/dist/package.json +34 -0
- package/index.html +196 -0
- package/package.json +24 -8
- package/publish.js +34 -0
- package/src/evaluator.ts +29 -0
- package/src/index.ts +10 -0
- package/src/parser.ts +480 -0
- package/src/reactivity.ts +185 -0
- package/tsconfig.json +23 -0
- package/vite.config.ts +16 -0
- package/index.es.js +0 -2
- package/index.es.js.map +0 -1
- package/index.umd.js +0 -2
- package/index.umd.js.map +0 -1
- /package/{index.d.ts → dist/index.d.ts} +0 -0
- /package/{src → dist/src}/evaluator.d.ts +0 -0
- /package/{src → dist/src}/index.d.ts +0 -0
- /package/{src → dist/src}/parser.d.ts +0 -0
- /package/{src → dist/src}/reactivity.d.ts +0 -0
- /package/{vite.config.d.ts → dist/vite.config.d.ts} +0 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.es.js","names":[],"sources":["../src/reactivity.ts","../src/evaluator.ts","../src/parser.ts","../src/index.ts"],"sourcesContent":["let activeEffect: symbol | null = null\nconst targetMap = new WeakMap<\n object,\n Map<string | symbol, Set<ReactiveEffect>>\n>()\nconst proxyMap = new WeakMap<object, any>()\nconst effectMap = new WeakMap<symbol, ReactiveEffect>()\n\nexport class ReactiveEffect {\n active = true\n deps: Set<Set<ReactiveEffect>> = new Set()\n\n constructor(public fn: () => void) {}\n\n run() {\n if (!this.active) return this.fn()\n\n this.cleanup()\n\n activeEffect = Symbol()\n effectMap.set(activeEffect, this)\n\n try {\n return this.fn()\n } finally {\n effectMap.delete(activeEffect)\n activeEffect = null\n }\n }\n\n stop() {\n if (this.active) {\n this.cleanup()\n this.active = false\n }\n }\n\n cleanup() {\n this.deps.forEach((dep) => dep.delete(this))\n this.deps.clear()\n }\n\n effect() {\n return {\n run: () => this.run(),\n stop: () => this.stop(),\n }\n }\n}\n\nexport function effect(fn: () => void) {\n const ref = new ReactiveEffect(fn)\n ref.run()\n return ref.effect()\n}\n\nexport function track(target: object, key: string | symbol) {\n if (activeEffect) {\n let depsMap = targetMap.get(target)\n if (!depsMap) {\n depsMap = new Map()\n targetMap.set(target, depsMap)\n }\n\n let dep = depsMap.get(key)\n if (!dep) {\n dep = new Set()\n depsMap.set(key, dep)\n }\n\n const active = effectMap.get(activeEffect)\n if (active) {\n dep.add(active)\n active.deps.add(dep)\n }\n }\n}\n\nexport function trigger(target: object, key: string | symbol) {\n const depsMap = targetMap.get(target)\n if (!depsMap) return\n\n const dep = depsMap.get(key)\n if (dep) {\n const effects = new Set(dep)\n effects.forEach((effect) => effect.run())\n }\n}\n\nexport function reactive<T extends object>(target: T): T {\n const notObject = typeof target !== 'object' || target === null\n if (notObject) return target\n\n if (\n target instanceof Map ||\n target instanceof Set ||\n target instanceof WeakMap ||\n target instanceof WeakSet ||\n target instanceof Date ||\n target instanceof RegExp ||\n (typeof Node === 'function' && target instanceof Node)\n ) {\n return target\n }\n\n const isReactive = Object.hasOwn(target, '_isReactive')\n if (isReactive) return target\n\n const existingProxy = proxyMap.get(target)\n if (existingProxy) return existingProxy\n\n const proxy = new Proxy(target, {\n get(obj, key, receiver) {\n if (key === '_isReactive') return true\n track(obj, key)\n\n const res = Reflect.get(obj, key, receiver)\n // deep reactivity\n return typeof res === 'object' && res !== null ? reactive(res) : res\n },\n set(obj, key, value, receiver) {\n const isArray = Array.isArray(obj)\n const oldValue = Reflect.get(obj, key, receiver)\n const hadKey =\n isArray && String(Number(key)) === key\n ? Number(key) < obj.length\n : Object.hasOwn(obj, key)\n\n const result = Reflect.set(obj, key, value, receiver)\n\n if (!hadKey) {\n trigger(obj, key)\n if (isArray && key !== 'length') {\n trigger(obj, 'length')\n }\n } else if (oldValue !== value) {\n trigger(obj, key)\n }\n\n return result\n },\n })\n\n proxyMap.set(target, proxy)\n return proxy\n}\n\nexport function traverse(value: any, seen = new Set()) {\n if (typeof value !== 'object' || value === null || seen.has(value)) {\n return value\n }\n seen.add(value)\n for (const key in value) {\n traverse(value[key], seen)\n }\n return value\n}\n\nexport function watch(\n source: any | (() => any),\n cb: (newValue: any, oldValue: any) => void,\n options?: { immediate?: boolean },\n) {\n let oldValue: any\n let isFirstRun = true\n\n const getter = source instanceof Function ? source : () => traverse(source)\n\n const runner = effect(() => {\n const newValue = getter()\n\n if (isFirstRun) {\n isFirstRun = false\n oldValue = newValue\n if (options?.immediate) {\n cb(newValue, undefined)\n }\n } else {\n cb(newValue, oldValue)\n oldValue = newValue\n }\n })\n\n return runner.stop\n}\n","export function evaluate(\n expression: string,\n context: Record<string, any> = {},\n) {\n try {\n const fn = new Function(`with(this) { return ${expression} }`)\n return fn.call(context)\n } catch {\n return undefined\n }\n}\n\nexport function evaluateEvent(\n $event: Event,\n expression: string,\n context: Record<string, any> = {},\n) {\n try {\n const exp = expression.trim()\n const isIdentifier = /^[a-zA-Z_$][0-9a-zA-Z_$.]*$/.test(exp)\n const code = `${exp} instanceof Function ? ${exp}.call(this, $event) : ${exp}`\n const result = isIdentifier ? code : exp\n const fn = new Function('$event', `with(this) { ${result} }`)\n\n fn.call(context, $event)\n } catch {\n console.warn(`[jsweb/ui] Error evaluating event: ${expression}`)\n }\n}\n","import { effect, reactive } from './reactivity'\nimport { evaluate, evaluateEvent } from './evaluator'\n\nexport type Context = Record<string, any>\n\ninterface BoundNode extends Node {\n _effects?: Array<() => void>\n}\n\nexport function cleanupTree(node: Node) {\n const bNode = node as BoundNode\n if (bNode._effects) {\n bNode._effects.forEach((stop) => stop())\n bNode._effects = []\n }\n const children = Array.from(node.childNodes)\n for (const child of children) cleanupTree(child)\n}\n\nexport function createContext(scope: any, context: Context = {}): Context {\n const reactiveScope = scope._isReactive ? scope : reactive(scope)\n\n return new Proxy(reactiveScope, {\n get(target, prop) {\n if (prop === '_isContext') return true\n if (prop in target) return Reflect.get(target, prop, target)\n if (prop in context) {\n return Reflect.get(context, prop, context)\n }\n return Reflect.get(target, prop, target)\n },\n set(target, prop, value) {\n if (prop in target) return Reflect.set(target, prop, value, target)\n if (prop in context) {\n return Reflect.set(context, prop, value, context)\n }\n return Reflect.set(target, prop, value, target)\n },\n has(target, prop) {\n if (prop in target) return true\n if (prop in context) return true\n return false\n },\n })\n}\n\nexport function parseNode(node: Node, context: Context) {\n if (node.nodeType !== Node.ELEMENT_NODE) return\n\n const el = node as HTMLElement\n const scope = processScope(el, context)\n if (!scope) return\n\n const forAttrs = ['ui:for', ':for']\n const forDirective = getDirectiveValue(el, forAttrs)\n if (forDirective) {\n removeDirectiveAttributes(el, forAttrs)\n processFor(el, forDirective, scope)\n return\n }\n\n const ifAttrs = ['ui:if', ':if']\n const ifDirective = getDirectiveValue(el, ifAttrs)\n if (ifDirective) {\n removeDirectiveAttributes(el, ifAttrs)\n processIf(el, ifDirective, scope)\n }\n\n processAttributes(el, scope)\n\n const children = Array.from(el.childNodes)\n for (const child of children) parseNode(child, scope)\n}\n\nexport function createScope(\n selectorOrElement: string | HTMLElement,\n context: Context = {},\n) {\n const el =\n typeof selectorOrElement === 'string'\n ? document.querySelector(selectorOrElement)\n : selectorOrElement\n\n if (el) {\n if (!context.$emit) {\n context.$emit = (eventName: string, detail?: any) => {\n el.dispatchEvent(\n new CustomEvent(eventName, { detail, bubbles: true, composed: true }),\n )\n }\n }\n\n if (!context.$refs) {\n context.$refs = new Map<string, any>()\n }\n\n parseNode(el, context)\n } else {\n console.warn('[jsweb/ui] Element not found:', selectorOrElement)\n }\n}\n\nfunction bindEffect(node: Node, fn: () => void) {\n const e = effect(fn)\n const bNode = node as BoundNode\n bNode._effects ??= []\n bNode._effects.push(e.stop)\n}\n\nfunction getDirectiveValue(el: HTMLElement, names: string[]) {\n for (const name of names) {\n const value = el.getAttribute(name)\n if (value !== null) return value\n }\n return null\n}\n\nfunction removeDirectiveAttributes(el: HTMLElement, names: string[]) {\n for (const name of names) {\n el.removeAttribute(name)\n }\n}\n\nfunction processScope(el: HTMLElement, context: Context) {\n const attrs = ['ui:scope', ':scope']\n const directive = getDirectiveValue(el, attrs)\n if (!directive) return context\n\n const scope = evaluate(directive, context)\n if (!scope) return undefined\n\n removeDirectiveAttributes(el, attrs)\n\n if (!scope.$emit) {\n scope.$emit = (event: string, detail?: any) => {\n el.dispatchEvent(\n new CustomEvent(event, { detail, bubbles: true, composed: true }),\n )\n }\n }\n\n if (!scope.$refs) {\n scope.$refs = context.$refs ?? new Map<string, any>()\n }\n\n return createContext(scope, context)\n}\n\nfunction processFor(el: HTMLElement, expr: string, context: Context) {\n const parent = el.parentNode\n if (!parent) return\n\n const match = /^\\s*(.+)\\s+(?:in|of)\\s+(.+)\\s*$/.exec(expr)\n if (!match) {\n return console.warn(`[jsweb/ui] Invalid ui:for expression: ${expr}`)\n }\n const [, itemName, listName] = match\n\n const keyAttr = ['ui:key', ':key']\n const keyDirective = getDirectiveValue(el, keyAttr)\n removeDirectiveAttributes(el, keyAttr)\n\n const uuid = crypto.randomUUID()\n const comment = document.createComment(` ui:for ${uuid} `)\n el.replaceWith(comment)\n\n interface RenderedNode {\n key: any\n el: HTMLElement\n scope: any\n }\n let renderedNodes: RenderedNode[] = []\n\n bindEffect(comment, () => {\n const list = evaluate(listName, context)\n\n if (!Array.isArray(list)) {\n renderedNodes.forEach((node) => {\n node.el.remove()\n cleanupTree(node.el)\n })\n renderedNodes = []\n return\n }\n\n const newNodes: RenderedNode[] = []\n const oldNodesByKey = new Map<any, RenderedNode>()\n renderedNodes.forEach((node) => oldNodesByKey.set(node.key, node))\n\n list.forEach((item, index) => {\n let key: any = index\n\n if (keyDirective) {\n const tempContext = createContext(\n { [itemName]: item, $index: index },\n context,\n )\n key = evaluate(keyDirective, tempContext)\n }\n\n const scope = { [itemName]: item, $index: index, $key: key }\n\n let node = oldNodesByKey.get(key)\n if (node) {\n // Reuse node\n node.scope[itemName] = item\n node.scope.$index = index\n node.scope.$key = key\n oldNodesByKey.delete(key)\n } else {\n // Create new node\n const clone = el.cloneNode(true) as HTMLElement\n const reactiveScope = reactive(scope)\n const localContext = createContext(reactiveScope, context)\n parseNode(clone, localContext)\n node = { key, el: clone, scope: reactiveScope }\n }\n\n newNodes.push(node)\n })\n\n // Remove un-reused nodes\n oldNodesByKey.forEach((node) => {\n node.el.remove()\n cleanupTree(node.el)\n })\n\n // Reorder and insert new DOM nodes\n let currentAnchor = comment.nextSibling\n newNodes.forEach((node) => {\n if (currentAnchor === node.el) {\n currentAnchor = currentAnchor.nextSibling\n } else {\n comment.parentNode?.insertBefore(node.el, currentAnchor)\n }\n })\n\n renderedNodes = newNodes\n })\n}\n\nfunction processIf(el: HTMLElement, expr: string, context: Context) {\n const parent = el.parentNode\n if (!parent) return\n\n const uuid = crypto.randomUUID()\n const comment = document.createComment(` ui:if ${uuid} `)\n el.before(comment)\n\n bindEffect(comment, () => {\n const val = evaluate(expr, context)\n if (val) {\n if (!el.parentNode) {\n comment.parentNode?.insertBefore(el, comment.nextSibling)\n }\n } else if (el.parentNode) {\n el.remove()\n }\n })\n}\n\nfunction processAttributes(el: HTMLElement, context: Context) {\n const attrs = Array.from(el.attributes)\n\n for (const attr of attrs) {\n const { name, value } = attr\n const isText = ['ui:text', ':text'].includes(name)\n const isTwoWayBind = ['ui:bind', ':bind'].includes(name)\n const isClassBind = ['ui:class', ':class'].includes(name)\n const isStyleBind = ['ui:style', ':style'].includes(name)\n const isRef = ['ui:ref', ':ref'].includes(name)\n const isAttrBind = name.startsWith('ui:') || name.startsWith(':')\n const isEvent = name.startsWith('ui@') || name.startsWith('@')\n\n if (isText) {\n processTextBinding(el, value, context)\n el.removeAttribute(name)\n } else if (isTwoWayBind) {\n processTwoWayBinding(el, value, context)\n el.removeAttribute(name)\n } else if (isClassBind) {\n processClassBinding(el, value, context)\n el.removeAttribute(name)\n } else if (isStyleBind) {\n processStyleBinding(el, value, context)\n el.removeAttribute(name)\n } else if (isRef) {\n processRef(el, value, context)\n el.removeAttribute(name)\n } else if (isAttrBind) {\n const bound = name.split(':').pop()!\n processAttrBinding(el, bound, value, context)\n el.removeAttribute(name)\n } else if (isEvent) {\n processEventBinding(el, name, value, context)\n el.removeAttribute(name)\n }\n }\n}\n\nfunction processRef(el: HTMLElement, expr: string, context: Context) {\n const refName = expr.trim().replace(/^['\"]|['\"]$/g, '')\n if (!refName) return\n\n const refs = context.$refs as Map<string, any>\n if (!refs) return\n\n const key = context.$key\n\n if (key !== undefined) {\n let group = refs.get(refName)\n if (!(group instanceof Map)) {\n group = new Map<any, HTMLElement>()\n refs.set(refName, group)\n }\n group.set(key, el)\n } else {\n refs.set(refName, el)\n }\n\n const bNode = el as BoundNode\n bNode._effects ??= []\n bNode._effects.push(() => {\n if (key !== undefined) {\n const group = refs.get(refName)\n if (group instanceof Map) {\n group.delete(key)\n if (group.size === 0) {\n refs.delete(refName)\n }\n }\n } else if (refs.get(refName) === el) {\n refs.delete(refName)\n }\n })\n}\n\nfunction processTextBinding(el: HTMLElement, expr: string, context: Context) {\n bindEffect(el, () => {\n const val = evaluate(expr, context)\n el.textContent = val !== undefined && val !== null ? String(val) : ''\n })\n}\n\nfunction processTwoWayBinding(el: HTMLElement, expr: string, context: Context) {\n const isCheckbox = el instanceof HTMLInputElement && el.type === 'checkbox'\n const isRadio = el instanceof HTMLInputElement && el.type === 'radio'\n\n // 1. Reactive state to DOM\n bindEffect(el, () => {\n const val = evaluate(expr, context)\n if (isCheckbox) {\n el.checked = !!val\n } else if (isRadio) {\n el.checked = el.value === String(val)\n } else {\n const target = el as\n | HTMLInputElement\n | HTMLSelectElement\n | HTMLTextAreaElement\n target.value = val == null ? '' : String(val)\n }\n })\n\n // 2. DOM to Reactive state\n const isChange = isCheckbox || isRadio || el instanceof HTMLSelectElement\n const eventName = isChange ? 'change' : 'input'\n el.addEventListener(eventName, ($event) => {\n const target = isCheckbox ? 'checked' : 'value'\n const value = `$event.target.${target}`\n evaluateEvent($event, `${expr} = ${value}`, context)\n })\n}\n\nfunction processAttrBinding(\n el: HTMLElement,\n attr: string,\n expr: string,\n context: Context,\n) {\n bindEffect(el, () => {\n const val = evaluate(expr, context)\n if (val === null || val === undefined || val === false) {\n el.removeAttribute(attr)\n } else if (val === true) {\n el.setAttribute(attr, '')\n } else {\n el.setAttribute(attr, String(val))\n }\n })\n}\n\nfunction processClassBinding(el: HTMLElement, expr: string, context: Context) {\n let oldClasses = new Set<string>()\n\n bindEffect(el, () => {\n const val = evaluate(expr, context)\n const newClasses = new Set<string>()\n const addClass = (c: string) => c && newClasses.add(c)\n const addClasses = (c: string) => c.split(/\\s+/).forEach(addClass)\n\n if (typeof val === 'string') addClasses(val)\n else if (Array.isArray(val)) {\n val.flat().forEach((c: any) => {\n if (typeof c === 'string') addClasses(c)\n })\n } else if (typeof val === 'object' && val !== null) {\n Object.entries(val).forEach(([c, condition]: [string, any]) => {\n if (condition) addClasses(c)\n })\n }\n\n oldClasses.forEach((c) => {\n if (!newClasses.has(c)) el.classList.remove(c)\n })\n newClasses.forEach((c) => {\n if (!oldClasses.has(c)) el.classList.add(c)\n })\n\n oldClasses = newClasses\n })\n}\n\nfunction processStyleBinding(el: HTMLElement, expr: string, context: Context) {\n let oldStyles: Record<string, any> = {}\n\n bindEffect(el, () => {\n const val = evaluate(expr, context)\n const newStyles = typeof val === 'object' && val !== null ? val : {}\n\n for (const key in oldStyles) {\n if (!(key in newStyles)) {\n ;(el.style as any)[key] = ''\n }\n }\n\n for (const key in newStyles) {\n if (oldStyles[key] !== newStyles[key]) {\n ;(el.style as any)[key] = newStyles[key]\n }\n }\n\n oldStyles = { ...newStyles }\n })\n}\n\nfunction processEventBinding(\n el: HTMLElement,\n evt: string,\n expr: string,\n context: Context,\n) {\n const refs = evt.split('@').pop()!\n const [name, ...modifiers] = refs.split('.')\n\n const isOutside = modifiers.includes('outside')\n const target = isOutside ? document : el\n\n const handler: EventListener = ($event: Event) => {\n if (!el.isConnected) return\n\n const isTargetNode = $event.target instanceof Node\n\n if (isOutside && isTargetNode && el.contains($event.target)) return\n if (modifiers.includes('self') && $event.target !== el) return\n\n if (modifiers.includes('prevent')) $event.preventDefault()\n if (modifiers.includes('stop')) $event.stopPropagation()\n\n evaluateEvent($event, expr, context)\n }\n\n target.addEventListener(name, handler)\n\n if (isOutside) {\n const bNode = el as BoundNode\n bNode._effects ??= []\n bNode._effects.push(() => target.removeEventListener(name, handler))\n }\n}\n","import { reactive, watch } from './reactivity'\nimport { createScope } from './parser'\n\nexport { reactive, watch, createScope }\n\nif (typeof window !== 'undefined') {\n const w = window as any\n w.jsweb = w.jsweb || {}\n w.jsweb.ui = { createScope, reactive, watch }\n}\n"],"mappings":"AAAA,IAAI,EAA8B,KAC5B,iBAAY,IAAI,QAIhB,iBAAW,IAAI,QACf,iBAAY,IAAI,QAET,EAAb,MAIqB,GAHnB,QAAS,EACT,oBAAiC,IAAI,IAErC,WAAA,CAAY,GAAO,KAAA,GAAA,CAAiB,CAEpC,GAAA,GACE,IAAK,KAAK,OAAQ,OAAO,KAAK,KAE9B,KAAK,UAEL,EAAe,SACf,EAAU,IAAI,EAAc,MAE5B,IACE,OAAO,KAAK,IACd,CAAA,QACE,EAAU,OAAO,GACjB,EAAe,IACjB,CACF,CAEA,IAAA,GACM,KAAK,SACP,KAAK,UACL,KAAK,QAAS,EAElB,CAEA,OAAA,GACE,KAAK,KAAK,QAAS,GAAQ,EAAI,OAAO,OACtC,KAAK,KAAK,OACZ,CAEA,MAAA,GACE,MAAO,CACL,IAAA,IAAW,KAAK,MAChB,KAAA,IAAY,KAAK,OAErB,GAGF,SAAgB,EAAO,GACrB,MAAM,EAAM,IAAI,EAAe,GAE/B,OADA,EAAI,MACG,EAAI,QACb,CAwBA,SAAgB,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GAAO,IAI9B,IAAK,MAAM,KAAO,EACZ,EAAU,KAAS,EAAU,KAC9B,EAAI,MAAc,GAAO,EAAU,IAIxC,EAAY,IAAK,IAErB,CAEA,SAAS,EACP,EACA,EACA,EACA,GAGA,MAAO,KAAS,GADH,EAAI,MAAM,KAAK,MACM,MAAM,KAElC,EAAY,EAAU,SAAS,WAC/B,EAAS,EAAY,SAAW,EAEhC,EAA0B,IAC9B,IAAK,EAAG,YAAa,OAErB,MAAM,EAAe,EAAO,kBAAkB,KAE1C,GAAa,GAAgB,EAAG,SAAS,EAAO,SAChD,EAAU,SAAS,SAAW,EAAO,SAAW,IAEhD,EAAU,SAAS,YAAY,EAAO,iBACtC,EAAU,SAAS,SAAS,EAAO,kBAEvC,EAAc,EAAQ,EAAM,KAK9B,GAFA,EAAO,iBAAiB,EAAM,GAE1B,EAAW,CACb,MAAM,EAAQ,EACd,EAAM,WAAa,GACnB,EAAM,SAAS,KAAA,IAAW,EAAO,oBAAoB,EAAM,GAC7D,CACF,CC1dA,GAAsB,oBAAX,OAAwB,CACjC,MAAM,EAAI,OACV,EAAE,MAAQ,EAAE,OAAS,CAAC,EACtB,EAAE,MAAM,GAAK,CAAE,cAAa,WAAU,QACxC"}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self)["@jsweb/ui"]={})}(this,function(e){Object.defineProperty(e,Symbol.toStringTag,{value:"Module"});var t=null,n=new WeakMap,o=new WeakMap,i=new WeakMap,s=class{fn;active=!0;deps=new Set;constructor(e){this.fn=e}run(){if(!this.active)return this.fn();this.cleanup(),t=Symbol(),i.set(t,this);try{return this.fn()}finally{i.delete(t),t=null}}stop(){this.active&&(this.cleanup(),this.active=!1)}cleanup(){this.deps.forEach(e=>e.delete(this)),this.deps.clear()}effect(){return{run:()=>this.run(),stop:()=>this.stop()}}};function c(e){const t=new s(e);return t.run(),t.effect()}function r(e,t){const o=n.get(e);if(!o)return;const i=o.get(t);i&&new Set(i).forEach(e=>e.run())}function f(e){if("object"!=typeof e||null===e)return e;if(e instanceof Map||e instanceof Set||e instanceof WeakMap||e instanceof WeakSet||e instanceof Date||e instanceof RegExp||"function"==typeof Node&&e instanceof Node)return e;if(Object.hasOwn(e,"_isReactive"))return e;const s=o.get(e);if(s)return s;const c=new Proxy(e,{get(e,o,s){if("_isReactive"===o)return!0;!function(e,o){if(t){let s=n.get(e);s||(s=new Map,n.set(e,s));let c=s.get(o);c||(c=new Set,s.set(o,c));const r=i.get(t);r&&(c.add(r),r.deps.add(c))}}(e,o);const c=Reflect.get(e,o,s);return"object"==typeof c&&null!==c?f(c):c},set(e,t,n,o){const i=Array.isArray(e),s=Reflect.get(e,t,o),c=i&&String(Number(t))===t?Number(t)<e.length:Object.hasOwn(e,t),f=Reflect.set(e,t,n,o);return c?s!==n&&r(e,t):(r(e,t),i&&"length"!==t&&r(e,"length")),f}});return o.set(e,c),c}function u(e,t=new Set){if("object"!=typeof e||null===e||t.has(e))return e;t.add(e);for(const n in e)u(e[n],t);return e}function a(e,t,n){let o,i=!0;const s=e instanceof Function?e:()=>u(e);return c(()=>{const e=s();i?(i=!1,o=e,n?.immediate&&t(e,void 0)):(t(e,o),o=e)}).stop}function l(e,t={}){try{return new Function(`with(this) { return ${e} }`).call(t)}catch{return}}function d(e,t,n={}){try{const o=t.trim(),i=/^[a-zA-Z_$][0-9a-zA-Z_$.]*$/.test(o);new Function("$event",`with(this) { ${i?`${o} instanceof Function ? ${o}.call(this, $event) : ${o}`:o} }`).call(n,e)}catch{console.warn(`[jsweb/ui] Error evaluating event: ${t}`)}}function p(e){const t=e;t._effects&&(t._effects.forEach(e=>e()),t._effects=[]);const n=Array.from(e.childNodes);for(const o of n)p(o)}function h(e,t={}){const n=e._isReactive?e:f(e);return new Proxy(n,{get:(e,n)=>"_isContext"===n||(n in e?Reflect.get(e,n,e):n in t?Reflect.get(t,n,t):Reflect.get(e,n,e)),set:(e,n,o)=>n in e?Reflect.set(e,n,o,e):n in t?Reflect.set(t,n,o,t):Reflect.set(e,n,o,e),has:(e,n)=>n in e||n in t})}function m(e,t){if(e.nodeType!==Node.ELEMENT_NODE)return;const n=e,o=function(e,t){const n=["ui:scope",":scope"],o=y(e,n);if(!o)return t;const i=l(o,t);if(!i)return;g(e,n),i.$emit||(i.$emit=(t,n)=>{e.dispatchEvent(new CustomEvent(t,{detail:n,bubbles:!0,composed:!0}))});i.$refs||(i.$refs=t.$refs??new Map);return h(i,t)}(n,t);if(!o)return;const i=["ui:for",":for"],s=y(n,i);if(s)return g(n,i),void function(e,t,n){if(!e.parentNode)return;const o=/^\s*(.+)\s+(?:in|of)\s+(.+)\s*$/.exec(t);if(!o)return console.warn(`[jsweb/ui] Invalid ui:for expression: ${t}`);const[,i,s]=o,c=["ui:key",":key"],r=y(e,c);g(e,c);const u=crypto.randomUUID(),a=document.createComment(` ui:for ${u} `);e.replaceWith(a);let d=[];v(a,()=>{const t=l(s,n);if(!Array.isArray(t))return d.forEach(e=>{e.el.remove(),p(e.el)}),void(d=[]);const o=[],c=new Map;d.forEach(e=>c.set(e.key,e)),t.forEach((t,s)=>{let u=s;if(r){const e=h({[i]:t,$index:s},n);u=l(r,e)}const a={[i]:t,$index:s,$key:u};let d=c.get(u);if(d)d.scope[i]=t,d.scope.$index=s,d.scope.$key=u,c.delete(u);else{const t=e.cloneNode(!0),o=f(a);m(t,h(o,n)),d={key:u,el:t,scope:o}}o.push(d)}),c.forEach(e=>{e.el.remove(),p(e.el)});let u=a.nextSibling;o.forEach(e=>{u===e.el?u=u.nextSibling:a.parentNode?.insertBefore(e.el,u)}),d=o})}(n,s,o);const c=["ui:if",":if"],r=y(n,c);r&&(g(n,c),function(e,t,n){if(!e.parentNode)return;const o=crypto.randomUUID(),i=document.createComment(` ui:if ${o} `);e.before(i),v(i,()=>{l(t,n)?e.parentNode||i.parentNode?.insertBefore(e,i.nextSibling):e.parentNode&&e.remove()})}(n,r,o)),function(e,t){const n=Array.from(e.attributes);for(const o of n){const{name:n,value:i}=o,s=["ui:text",":text"].includes(n),c=["ui:bind",":bind"].includes(n),r=["ui:class",":class"].includes(n),f=["ui:style",":style"].includes(n),u=["ui:ref",":ref"].includes(n),a=n.startsWith("ui:")||n.startsWith(":"),l=n.startsWith("ui@")||n.startsWith("@");s?($(e,i,t),e.removeAttribute(n)):c?(E(e,i,t),e.removeAttribute(n)):r?(S(e,i,t),e.removeAttribute(n)):f?(x(e,i,t),e.removeAttribute(n)):u?(w(e,i,t),e.removeAttribute(n)):a?(A(e,n.split(":").pop(),i,t),e.removeAttribute(n)):l&&(j(e,n,i,t),e.removeAttribute(n))}}(n,o);const u=Array.from(n.childNodes);for(const f of u)m(f,o)}function b(e,t={}){const n="string"==typeof e?document.querySelector(e):e;n?(t.$emit||(t.$emit=(e,t)=>{n.dispatchEvent(new CustomEvent(e,{detail:t,bubbles:!0,composed:!0}))}),t.$refs||(t.$refs=new Map),m(n,t)):console.warn("[jsweb/ui] Element not found:",e)}function v(e,t){const n=c(t),o=e;o._effects??=[],o._effects.push(n.stop)}function y(e,t){for(const n of t){const t=e.getAttribute(n);if(null!==t)return t}return null}function g(e,t){for(const n of t)e.removeAttribute(n)}function w(e,t,n){const o=t.trim().replace(/^['"]|['"]$/g,"");if(!o)return;const i=n.$refs;if(!i)return;const s=n.$key;if(void 0!==s){let t=i.get(o);t instanceof Map||(t=new Map,i.set(o,t)),t.set(s,e)}else i.set(o,e);const c=e;c._effects??=[],c._effects.push(()=>{if(void 0!==s){const e=i.get(o);e instanceof Map&&(e.delete(s),0===e.size&&i.delete(o))}else i.get(o)===e&&i.delete(o)})}function $(e,t,n){v(e,()=>{const o=l(t,n);e.textContent=null!=o?String(o):""})}function E(e,t,n){const o=e instanceof HTMLInputElement&&"checkbox"===e.type,i=e instanceof HTMLInputElement&&"radio"===e.type;v(e,()=>{const s=l(t,n);if(o)e.checked=!!s;else if(i)e.checked=e.value===String(s);else{e.value=null==s?"":String(s)}});const s=o||i||e instanceof HTMLSelectElement?"change":"input";e.addEventListener(s,e=>{d(e,`${t} = ${"$event.target."+(o?"checked":"value")}`,n)})}function A(e,t,n,o){v(e,()=>{const i=l(n,o);null==i||!1===i?e.removeAttribute(t):!0===i?e.setAttribute(t,""):e.setAttribute(t,String(i))})}function S(e,t,n){let o=new Set;v(e,()=>{const i=l(t,n),s=new Set,c=e=>e&&s.add(e),r=e=>e.split(/\s+/).forEach(c);"string"==typeof i?r(i):Array.isArray(i)?i.flat().forEach(e=>{"string"==typeof e&&r(e)}):"object"==typeof i&&null!==i&&Object.entries(i).forEach(([e,t])=>{t&&r(e)}),o.forEach(t=>{s.has(t)||e.classList.remove(t)}),s.forEach(t=>{o.has(t)||e.classList.add(t)}),o=s})}function x(e,t,n){let o={};v(e,()=>{const i=l(t,n),s="object"==typeof i&&null!==i?i:{};for(const t in o)t in s||(e.style[t]="");for(const t in s)o[t]!==s[t]&&(e.style[t]=s[t]);o={...s}})}function j(e,t,n,o){const[i,...s]=t.split("@").pop().split("."),c=s.includes("outside"),r=c?document:e,f=t=>{if(!e.isConnected)return;const i=t.target instanceof Node;c&&i&&e.contains(t.target)||s.includes("self")&&t.target!==e||(s.includes("prevent")&&t.preventDefault(),s.includes("stop")&&t.stopPropagation(),d(t,n,o))};if(r.addEventListener(i,f),c){const t=e;t._effects??=[],t._effects.push(()=>r.removeEventListener(i,f))}}if("undefined"!=typeof window){const e=window;e.jsweb=e.jsweb||{},e.jsweb.ui={createScope:b,reactive:f,watch:a}}e.createScope=b,e.reactive=f,e.watch=a});
|
|
2
|
+
//# sourceMappingURL=index.umd.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.umd.js","names":[],"sources":["../src/reactivity.ts","../src/evaluator.ts","../src/parser.ts","../src/index.ts"],"sourcesContent":["let activeEffect: symbol | null = null\nconst targetMap = new WeakMap<\n object,\n Map<string | symbol, Set<ReactiveEffect>>\n>()\nconst proxyMap = new WeakMap<object, any>()\nconst effectMap = new WeakMap<symbol, ReactiveEffect>()\n\nexport class ReactiveEffect {\n active = true\n deps: Set<Set<ReactiveEffect>> = new Set()\n\n constructor(public fn: () => void) {}\n\n run() {\n if (!this.active) return this.fn()\n\n this.cleanup()\n\n activeEffect = Symbol()\n effectMap.set(activeEffect, this)\n\n try {\n return this.fn()\n } finally {\n effectMap.delete(activeEffect)\n activeEffect = null\n }\n }\n\n stop() {\n if (this.active) {\n this.cleanup()\n this.active = false\n }\n }\n\n cleanup() {\n this.deps.forEach((dep) => dep.delete(this))\n this.deps.clear()\n }\n\n effect() {\n return {\n run: () => this.run(),\n stop: () => this.stop(),\n }\n }\n}\n\nexport function effect(fn: () => void) {\n const ref = new ReactiveEffect(fn)\n ref.run()\n return ref.effect()\n}\n\nexport function track(target: object, key: string | symbol) {\n if (activeEffect) {\n let depsMap = targetMap.get(target)\n if (!depsMap) {\n depsMap = new Map()\n targetMap.set(target, depsMap)\n }\n\n let dep = depsMap.get(key)\n if (!dep) {\n dep = new Set()\n depsMap.set(key, dep)\n }\n\n const active = effectMap.get(activeEffect)\n if (active) {\n dep.add(active)\n active.deps.add(dep)\n }\n }\n}\n\nexport function trigger(target: object, key: string | symbol) {\n const depsMap = targetMap.get(target)\n if (!depsMap) return\n\n const dep = depsMap.get(key)\n if (dep) {\n const effects = new Set(dep)\n effects.forEach((effect) => effect.run())\n }\n}\n\nexport function reactive<T extends object>(target: T): T {\n const notObject = typeof target !== 'object' || target === null\n if (notObject) return target\n\n if (\n target instanceof Map ||\n target instanceof Set ||\n target instanceof WeakMap ||\n target instanceof WeakSet ||\n target instanceof Date ||\n target instanceof RegExp ||\n (typeof Node === 'function' && target instanceof Node)\n ) {\n return target\n }\n\n const isReactive = Object.hasOwn(target, '_isReactive')\n if (isReactive) return target\n\n const existingProxy = proxyMap.get(target)\n if (existingProxy) return existingProxy\n\n const proxy = new Proxy(target, {\n get(obj, key, receiver) {\n if (key === '_isReactive') return true\n track(obj, key)\n\n const res = Reflect.get(obj, key, receiver)\n // deep reactivity\n return typeof res === 'object' && res !== null ? reactive(res) : res\n },\n set(obj, key, value, receiver) {\n const isArray = Array.isArray(obj)\n const oldValue = Reflect.get(obj, key, receiver)\n const hadKey =\n isArray && String(Number(key)) === key\n ? Number(key) < obj.length\n : Object.hasOwn(obj, key)\n\n const result = Reflect.set(obj, key, value, receiver)\n\n if (!hadKey) {\n trigger(obj, key)\n if (isArray && key !== 'length') {\n trigger(obj, 'length')\n }\n } else if (oldValue !== value) {\n trigger(obj, key)\n }\n\n return result\n },\n })\n\n proxyMap.set(target, proxy)\n return proxy\n}\n\nexport function traverse(value: any, seen = new Set()) {\n if (typeof value !== 'object' || value === null || seen.has(value)) {\n return value\n }\n seen.add(value)\n for (const key in value) {\n traverse(value[key], seen)\n }\n return value\n}\n\nexport function watch(\n source: any | (() => any),\n cb: (newValue: any, oldValue: any) => void,\n options?: { immediate?: boolean },\n) {\n let oldValue: any\n let isFirstRun = true\n\n const getter = source instanceof Function ? source : () => traverse(source)\n\n const runner = effect(() => {\n const newValue = getter()\n\n if (isFirstRun) {\n isFirstRun = false\n oldValue = newValue\n if (options?.immediate) {\n cb(newValue, undefined)\n }\n } else {\n cb(newValue, oldValue)\n oldValue = newValue\n }\n })\n\n return runner.stop\n}\n","export function evaluate(\n expression: string,\n context: Record<string, any> = {},\n) {\n try {\n const fn = new Function(`with(this) { return ${expression} }`)\n return fn.call(context)\n } catch {\n return undefined\n }\n}\n\nexport function evaluateEvent(\n $event: Event,\n expression: string,\n context: Record<string, any> = {},\n) {\n try {\n const exp = expression.trim()\n const isIdentifier = /^[a-zA-Z_$][0-9a-zA-Z_$.]*$/.test(exp)\n const code = `${exp} instanceof Function ? ${exp}.call(this, $event) : ${exp}`\n const result = isIdentifier ? code : exp\n const fn = new Function('$event', `with(this) { ${result} }`)\n\n fn.call(context, $event)\n } catch {\n console.warn(`[jsweb/ui] Error evaluating event: ${expression}`)\n }\n}\n","import { effect, reactive } from './reactivity'\nimport { evaluate, evaluateEvent } from './evaluator'\n\nexport type Context = Record<string, any>\n\ninterface BoundNode extends Node {\n _effects?: Array<() => void>\n}\n\nexport function cleanupTree(node: Node) {\n const bNode = node as BoundNode\n if (bNode._effects) {\n bNode._effects.forEach((stop) => stop())\n bNode._effects = []\n }\n const children = Array.from(node.childNodes)\n for (const child of children) cleanupTree(child)\n}\n\nexport function createContext(scope: any, context: Context = {}): Context {\n const reactiveScope = scope._isReactive ? scope : reactive(scope)\n\n return new Proxy(reactiveScope, {\n get(target, prop) {\n if (prop === '_isContext') return true\n if (prop in target) return Reflect.get(target, prop, target)\n if (prop in context) {\n return Reflect.get(context, prop, context)\n }\n return Reflect.get(target, prop, target)\n },\n set(target, prop, value) {\n if (prop in target) return Reflect.set(target, prop, value, target)\n if (prop in context) {\n return Reflect.set(context, prop, value, context)\n }\n return Reflect.set(target, prop, value, target)\n },\n has(target, prop) {\n if (prop in target) return true\n if (prop in context) return true\n return false\n },\n })\n}\n\nexport function parseNode(node: Node, context: Context) {\n if (node.nodeType !== Node.ELEMENT_NODE) return\n\n const el = node as HTMLElement\n const scope = processScope(el, context)\n if (!scope) return\n\n const forAttrs = ['ui:for', ':for']\n const forDirective = getDirectiveValue(el, forAttrs)\n if (forDirective) {\n removeDirectiveAttributes(el, forAttrs)\n processFor(el, forDirective, scope)\n return\n }\n\n const ifAttrs = ['ui:if', ':if']\n const ifDirective = getDirectiveValue(el, ifAttrs)\n if (ifDirective) {\n removeDirectiveAttributes(el, ifAttrs)\n processIf(el, ifDirective, scope)\n }\n\n processAttributes(el, scope)\n\n const children = Array.from(el.childNodes)\n for (const child of children) parseNode(child, scope)\n}\n\nexport function createScope(\n selectorOrElement: string | HTMLElement,\n context: Context = {},\n) {\n const el =\n typeof selectorOrElement === 'string'\n ? document.querySelector(selectorOrElement)\n : selectorOrElement\n\n if (el) {\n if (!context.$emit) {\n context.$emit = (eventName: string, detail?: any) => {\n el.dispatchEvent(\n new CustomEvent(eventName, { detail, bubbles: true, composed: true }),\n )\n }\n }\n\n if (!context.$refs) {\n context.$refs = new Map<string, any>()\n }\n\n parseNode(el, context)\n } else {\n console.warn('[jsweb/ui] Element not found:', selectorOrElement)\n }\n}\n\nfunction bindEffect(node: Node, fn: () => void) {\n const e = effect(fn)\n const bNode = node as BoundNode\n bNode._effects ??= []\n bNode._effects.push(e.stop)\n}\n\nfunction getDirectiveValue(el: HTMLElement, names: string[]) {\n for (const name of names) {\n const value = el.getAttribute(name)\n if (value !== null) return value\n }\n return null\n}\n\nfunction removeDirectiveAttributes(el: HTMLElement, names: string[]) {\n for (const name of names) {\n el.removeAttribute(name)\n }\n}\n\nfunction processScope(el: HTMLElement, context: Context) {\n const attrs = ['ui:scope', ':scope']\n const directive = getDirectiveValue(el, attrs)\n if (!directive) return context\n\n const scope = evaluate(directive, context)\n if (!scope) return undefined\n\n removeDirectiveAttributes(el, attrs)\n\n if (!scope.$emit) {\n scope.$emit = (event: string, detail?: any) => {\n el.dispatchEvent(\n new CustomEvent(event, { detail, bubbles: true, composed: true }),\n )\n }\n }\n\n if (!scope.$refs) {\n scope.$refs = context.$refs ?? new Map<string, any>()\n }\n\n return createContext(scope, context)\n}\n\nfunction processFor(el: HTMLElement, expr: string, context: Context) {\n const parent = el.parentNode\n if (!parent) return\n\n const match = /^\\s*(.+)\\s+(?:in|of)\\s+(.+)\\s*$/.exec(expr)\n if (!match) {\n return console.warn(`[jsweb/ui] Invalid ui:for expression: ${expr}`)\n }\n const [, itemName, listName] = match\n\n const keyAttr = ['ui:key', ':key']\n const keyDirective = getDirectiveValue(el, keyAttr)\n removeDirectiveAttributes(el, keyAttr)\n\n const uuid = crypto.randomUUID()\n const comment = document.createComment(` ui:for ${uuid} `)\n el.replaceWith(comment)\n\n interface RenderedNode {\n key: any\n el: HTMLElement\n scope: any\n }\n let renderedNodes: RenderedNode[] = []\n\n bindEffect(comment, () => {\n const list = evaluate(listName, context)\n\n if (!Array.isArray(list)) {\n renderedNodes.forEach((node) => {\n node.el.remove()\n cleanupTree(node.el)\n })\n renderedNodes = []\n return\n }\n\n const newNodes: RenderedNode[] = []\n const oldNodesByKey = new Map<any, RenderedNode>()\n renderedNodes.forEach((node) => oldNodesByKey.set(node.key, node))\n\n list.forEach((item, index) => {\n let key: any = index\n\n if (keyDirective) {\n const tempContext = createContext(\n { [itemName]: item, $index: index },\n context,\n )\n key = evaluate(keyDirective, tempContext)\n }\n\n const scope = { [itemName]: item, $index: index, $key: key }\n\n let node = oldNodesByKey.get(key)\n if (node) {\n // Reuse node\n node.scope[itemName] = item\n node.scope.$index = index\n node.scope.$key = key\n oldNodesByKey.delete(key)\n } else {\n // Create new node\n const clone = el.cloneNode(true) as HTMLElement\n const reactiveScope = reactive(scope)\n const localContext = createContext(reactiveScope, context)\n parseNode(clone, localContext)\n node = { key, el: clone, scope: reactiveScope }\n }\n\n newNodes.push(node)\n })\n\n // Remove un-reused nodes\n oldNodesByKey.forEach((node) => {\n node.el.remove()\n cleanupTree(node.el)\n })\n\n // Reorder and insert new DOM nodes\n let currentAnchor = comment.nextSibling\n newNodes.forEach((node) => {\n if (currentAnchor === node.el) {\n currentAnchor = currentAnchor.nextSibling\n } else {\n comment.parentNode?.insertBefore(node.el, currentAnchor)\n }\n })\n\n renderedNodes = newNodes\n })\n}\n\nfunction processIf(el: HTMLElement, expr: string, context: Context) {\n const parent = el.parentNode\n if (!parent) return\n\n const uuid = crypto.randomUUID()\n const comment = document.createComment(` ui:if ${uuid} `)\n el.before(comment)\n\n bindEffect(comment, () => {\n const val = evaluate(expr, context)\n if (val) {\n if (!el.parentNode) {\n comment.parentNode?.insertBefore(el, comment.nextSibling)\n }\n } else if (el.parentNode) {\n el.remove()\n }\n })\n}\n\nfunction processAttributes(el: HTMLElement, context: Context) {\n const attrs = Array.from(el.attributes)\n\n for (const attr of attrs) {\n const { name, value } = attr\n const isText = ['ui:text', ':text'].includes(name)\n const isTwoWayBind = ['ui:bind', ':bind'].includes(name)\n const isClassBind = ['ui:class', ':class'].includes(name)\n const isStyleBind = ['ui:style', ':style'].includes(name)\n const isRef = ['ui:ref', ':ref'].includes(name)\n const isAttrBind = name.startsWith('ui:') || name.startsWith(':')\n const isEvent = name.startsWith('ui@') || name.startsWith('@')\n\n if (isText) {\n processTextBinding(el, value, context)\n el.removeAttribute(name)\n } else if (isTwoWayBind) {\n processTwoWayBinding(el, value, context)\n el.removeAttribute(name)\n } else if (isClassBind) {\n processClassBinding(el, value, context)\n el.removeAttribute(name)\n } else if (isStyleBind) {\n processStyleBinding(el, value, context)\n el.removeAttribute(name)\n } else if (isRef) {\n processRef(el, value, context)\n el.removeAttribute(name)\n } else if (isAttrBind) {\n const bound = name.split(':').pop()!\n processAttrBinding(el, bound, value, context)\n el.removeAttribute(name)\n } else if (isEvent) {\n processEventBinding(el, name, value, context)\n el.removeAttribute(name)\n }\n }\n}\n\nfunction processRef(el: HTMLElement, expr: string, context: Context) {\n const refName = expr.trim().replace(/^['\"]|['\"]$/g, '')\n if (!refName) return\n\n const refs = context.$refs as Map<string, any>\n if (!refs) return\n\n const key = context.$key\n\n if (key !== undefined) {\n let group = refs.get(refName)\n if (!(group instanceof Map)) {\n group = new Map<any, HTMLElement>()\n refs.set(refName, group)\n }\n group.set(key, el)\n } else {\n refs.set(refName, el)\n }\n\n const bNode = el as BoundNode\n bNode._effects ??= []\n bNode._effects.push(() => {\n if (key !== undefined) {\n const group = refs.get(refName)\n if (group instanceof Map) {\n group.delete(key)\n if (group.size === 0) {\n refs.delete(refName)\n }\n }\n } else if (refs.get(refName) === el) {\n refs.delete(refName)\n }\n })\n}\n\nfunction processTextBinding(el: HTMLElement, expr: string, context: Context) {\n bindEffect(el, () => {\n const val = evaluate(expr, context)\n el.textContent = val !== undefined && val !== null ? String(val) : ''\n })\n}\n\nfunction processTwoWayBinding(el: HTMLElement, expr: string, context: Context) {\n const isCheckbox = el instanceof HTMLInputElement && el.type === 'checkbox'\n const isRadio = el instanceof HTMLInputElement && el.type === 'radio'\n\n // 1. Reactive state to DOM\n bindEffect(el, () => {\n const val = evaluate(expr, context)\n if (isCheckbox) {\n el.checked = !!val\n } else if (isRadio) {\n el.checked = el.value === String(val)\n } else {\n const target = el as\n | HTMLInputElement\n | HTMLSelectElement\n | HTMLTextAreaElement\n target.value = val == null ? '' : String(val)\n }\n })\n\n // 2. DOM to Reactive state\n const isChange = isCheckbox || isRadio || el instanceof HTMLSelectElement\n const eventName = isChange ? 'change' : 'input'\n el.addEventListener(eventName, ($event) => {\n const target = isCheckbox ? 'checked' : 'value'\n const value = `$event.target.${target}`\n evaluateEvent($event, `${expr} = ${value}`, context)\n })\n}\n\nfunction processAttrBinding(\n el: HTMLElement,\n attr: string,\n expr: string,\n context: Context,\n) {\n bindEffect(el, () => {\n const val = evaluate(expr, context)\n if (val === null || val === undefined || val === false) {\n el.removeAttribute(attr)\n } else if (val === true) {\n el.setAttribute(attr, '')\n } else {\n el.setAttribute(attr, String(val))\n }\n })\n}\n\nfunction processClassBinding(el: HTMLElement, expr: string, context: Context) {\n let oldClasses = new Set<string>()\n\n bindEffect(el, () => {\n const val = evaluate(expr, context)\n const newClasses = new Set<string>()\n const addClass = (c: string) => c && newClasses.add(c)\n const addClasses = (c: string) => c.split(/\\s+/).forEach(addClass)\n\n if (typeof val === 'string') addClasses(val)\n else if (Array.isArray(val)) {\n val.flat().forEach((c: any) => {\n if (typeof c === 'string') addClasses(c)\n })\n } else if (typeof val === 'object' && val !== null) {\n Object.entries(val).forEach(([c, condition]: [string, any]) => {\n if (condition) addClasses(c)\n })\n }\n\n oldClasses.forEach((c) => {\n if (!newClasses.has(c)) el.classList.remove(c)\n })\n newClasses.forEach((c) => {\n if (!oldClasses.has(c)) el.classList.add(c)\n })\n\n oldClasses = newClasses\n })\n}\n\nfunction processStyleBinding(el: HTMLElement, expr: string, context: Context) {\n let oldStyles: Record<string, any> = {}\n\n bindEffect(el, () => {\n const val = evaluate(expr, context)\n const newStyles = typeof val === 'object' && val !== null ? val : {}\n\n for (const key in oldStyles) {\n if (!(key in newStyles)) {\n ;(el.style as any)[key] = ''\n }\n }\n\n for (const key in newStyles) {\n if (oldStyles[key] !== newStyles[key]) {\n ;(el.style as any)[key] = newStyles[key]\n }\n }\n\n oldStyles = { ...newStyles }\n })\n}\n\nfunction processEventBinding(\n el: HTMLElement,\n evt: string,\n expr: string,\n context: Context,\n) {\n const refs = evt.split('@').pop()!\n const [name, ...modifiers] = refs.split('.')\n\n const isOutside = modifiers.includes('outside')\n const target = isOutside ? document : el\n\n const handler: EventListener = ($event: Event) => {\n if (!el.isConnected) return\n\n const isTargetNode = $event.target instanceof Node\n\n if (isOutside && isTargetNode && el.contains($event.target)) return\n if (modifiers.includes('self') && $event.target !== el) return\n\n if (modifiers.includes('prevent')) $event.preventDefault()\n if (modifiers.includes('stop')) $event.stopPropagation()\n\n evaluateEvent($event, expr, context)\n }\n\n target.addEventListener(name, handler)\n\n if (isOutside) {\n const bNode = el as BoundNode\n bNode._effects ??= []\n bNode._effects.push(() => target.removeEventListener(name, handler))\n }\n}\n","import { reactive, watch } from './reactivity'\nimport { createScope } from './parser'\n\nexport { reactive, watch, createScope }\n\nif (typeof window !== 'undefined') {\n const w = window as any\n w.jsweb = w.jsweb || {}\n w.jsweb.ui = { createScope, reactive, watch }\n}\n"],"mappings":"mSAAA,IAAI,EAA8B,KAC5B,EAAY,IAAI,QAIhB,EAAW,IAAI,QACf,EAAY,IAAI,QAET,EAAb,MAIqB,GAHnB,QAAS,EACT,KAAiC,IAAI,IAErC,WAAA,CAAY,GAAO,KAAA,GAAA,CAAiB,CAEpC,GAAA,GACE,IAAK,KAAK,OAAQ,OAAO,KAAK,KAE9B,KAAK,UAEL,EAAe,SACf,EAAU,IAAI,EAAc,MAE5B,IACE,OAAO,KAAK,IACd,CAAA,QACE,EAAU,OAAO,GACjB,EAAe,IACjB,CACF,CAEA,IAAA,GACM,KAAK,SACP,KAAK,UACL,KAAK,QAAS,EAElB,CAEA,OAAA,GACE,KAAK,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12
|
+
],
|
|
13
|
+
"homepage": "https://github.com/jsweb/ui#readme",
|
|
14
|
+
"bugs": {
|
|
15
|
+
"url": "https://github.com/jsweb/ui/issues"
|
|
16
|
+
},
|
|
17
|
+
"repository": {
|
|
18
|
+
"type": "git",
|
|
19
|
+
"url": "git+https://github.com/jsweb/ui.git"
|
|
20
|
+
},
|
|
21
|
+
"license": "MIT",
|
|
22
|
+
"author": "Alex Bruno Cáceres <email@alexbruno.dev>",
|
|
23
|
+
"type": "module",
|
|
24
|
+
"main": "index.umd.js",
|
|
25
|
+
"module": "index.es.js",
|
|
26
|
+
"types": "index.d.ts",
|
|
27
|
+
"exports": {
|
|
28
|
+
".": {
|
|
29
|
+
"import": "./index.es.js",
|
|
30
|
+
"require": "./index.umd.js",
|
|
31
|
+
"types": "./index.d.ts"
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
}
|
package/index.html
ADDED
|
@@ -0,0 +1,196 @@
|
|
|
1
|
+
<!doctype html>
|
|
2
|
+
<html lang="en">
|
|
3
|
+
<head>
|
|
4
|
+
<meta charset="UTF-8" />
|
|
5
|
+
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
|
6
|
+
<title>JS Web UI Test</title>
|
|
7
|
+
<style>
|
|
8
|
+
.box {
|
|
9
|
+
padding: 20px;
|
|
10
|
+
border-radius: 8px;
|
|
11
|
+
transition: all 0.3s ease;
|
|
12
|
+
margin-bottom: 10px;
|
|
13
|
+
color: white;
|
|
14
|
+
}
|
|
15
|
+
.active {
|
|
16
|
+
box-shadow: 0 0 15px rgba(0, 0, 0, 0.3);
|
|
17
|
+
transform: scale(1.02);
|
|
18
|
+
}
|
|
19
|
+
</style>
|
|
20
|
+
<script type="module">
|
|
21
|
+
import { createScope, reactive } from './src/index.ts'
|
|
22
|
+
|
|
23
|
+
const scope = reactive({
|
|
24
|
+
count: 0,
|
|
25
|
+
inc: 'Incremento',
|
|
26
|
+
dec: 'Decremento',
|
|
27
|
+
model: 'Exemplo',
|
|
28
|
+
items: ['A', 'B', 'C'],
|
|
29
|
+
active: false,
|
|
30
|
+
color: '#42b883',
|
|
31
|
+
|
|
32
|
+
get computedItems() {
|
|
33
|
+
return this.items.map((value, index) => {
|
|
34
|
+
return { value, index }
|
|
35
|
+
})
|
|
36
|
+
},
|
|
37
|
+
|
|
38
|
+
increment() {
|
|
39
|
+
this.count++
|
|
40
|
+
},
|
|
41
|
+
decrement() {
|
|
42
|
+
this.count--
|
|
43
|
+
},
|
|
44
|
+
zero() {
|
|
45
|
+
this.count = 0
|
|
46
|
+
},
|
|
47
|
+
addItem() {
|
|
48
|
+
const value = Date.now()
|
|
49
|
+
this.items.push(value)
|
|
50
|
+
},
|
|
51
|
+
removeItem() {
|
|
52
|
+
this.items.pop()
|
|
53
|
+
},
|
|
54
|
+
logEvent(e, ...args) {
|
|
55
|
+
console.log('Evento recebido:', e, args)
|
|
56
|
+
this.items.push(`Evento ${e.type}`)
|
|
57
|
+
},
|
|
58
|
+
toggleActive() {
|
|
59
|
+
this.active = !this.active
|
|
60
|
+
},
|
|
61
|
+
handleCustomEvent(e) {
|
|
62
|
+
alert(`Custom event received: ${e.detail.message}`)
|
|
63
|
+
this.items.push(`Custom Event: ${e.detail.message}`)
|
|
64
|
+
},
|
|
65
|
+
focusInputModel() {
|
|
66
|
+
const input = this.$refs.get('inputModel')
|
|
67
|
+
if (input) {
|
|
68
|
+
input.focus()
|
|
69
|
+
input.style.outline = '2px solid blue'
|
|
70
|
+
console.log('Single ref resgatada com sucesso:', input)
|
|
71
|
+
}
|
|
72
|
+
},
|
|
73
|
+
focusListItem(idx) {
|
|
74
|
+
const inputMap = this.$refs.get('itemInput')
|
|
75
|
+
console.log('Nested Map de refs da lista:', inputMap)
|
|
76
|
+
const el = inputMap?.get(idx)
|
|
77
|
+
if (el) {
|
|
78
|
+
el.focus()
|
|
79
|
+
el.select()
|
|
80
|
+
console.log(`Elemento da chave ${idx} resgatado:`, el)
|
|
81
|
+
}
|
|
82
|
+
},
|
|
83
|
+
logRefs() {
|
|
84
|
+
console.log('Todas as $refs indexadas no Map:', this.$refs)
|
|
85
|
+
alert(`Refs mapeadas: ${Array.from(this.$refs.keys()).join(', ')}`)
|
|
86
|
+
},
|
|
87
|
+
})
|
|
88
|
+
|
|
89
|
+
window.scope = scope
|
|
90
|
+
|
|
91
|
+
createScope('body', { scope })
|
|
92
|
+
</script>
|
|
93
|
+
</head>
|
|
94
|
+
<body>
|
|
95
|
+
<div :scope="scope">
|
|
96
|
+
<h1>JS Web UI</h1>
|
|
97
|
+
<p>Contador: <span :text="count"></span></p>
|
|
98
|
+
<button :text="inc" @click="increment">+</button>
|
|
99
|
+
<button :text="dec" @click="decrement">-</button>
|
|
100
|
+
|
|
101
|
+
<div style="margin-top: 20px">
|
|
102
|
+
<button @click="zero" :disabled="!count">Zerar</button>
|
|
103
|
+
</div>
|
|
104
|
+
|
|
105
|
+
<div
|
|
106
|
+
:if="count > 0"
|
|
107
|
+
style="margin-top: 20px; padding: 10px; border: 1px solid green"
|
|
108
|
+
>
|
|
109
|
+
O contador é maior que zero!
|
|
110
|
+
</div>
|
|
111
|
+
|
|
112
|
+
<div style="margin-top: 20px">
|
|
113
|
+
<h3>Lista:</h3>
|
|
114
|
+
<div style="margin-bottom: 10px">
|
|
115
|
+
<input
|
|
116
|
+
type="text"
|
|
117
|
+
:bind="model"
|
|
118
|
+
:ref="inputModel"
|
|
119
|
+
placeholder="Digite algo..."
|
|
120
|
+
/>
|
|
121
|
+
<p>Você vai adicionar: <strong :text="model"></strong></p>
|
|
122
|
+
<button @click="addItem">Adicionar Item</button>
|
|
123
|
+
<button @click="removeItem">Remover Item</button>
|
|
124
|
+
<button @click="focusInputModel">
|
|
125
|
+
Focar Campo via this.$refs.get('inputModel')
|
|
126
|
+
</button>
|
|
127
|
+
<button @click="logRefs">Inspecionar $refs no Console</button>
|
|
128
|
+
<button @click="logEvent">Testar Evento (Sem Parênteses)</button>
|
|
129
|
+
<button @click="logEvent($event, 'A', 'B', 'C')">
|
|
130
|
+
Testar Evento (Com Parênteses)
|
|
131
|
+
</button>
|
|
132
|
+
</div>
|
|
133
|
+
<ul>
|
|
134
|
+
<li :for="item of computedItems" :key="item.index" :ref="itemRow">
|
|
135
|
+
<span :text="item.index"></span>:
|
|
136
|
+
<input type="text" :value="item.value" :ref="itemInput" />
|
|
137
|
+
<button @click="focusListItem(item.index)">
|
|
138
|
+
Focar este input ($refs.get('itemInput').get($key))
|
|
139
|
+
</button>
|
|
140
|
+
</li>
|
|
141
|
+
</ul>
|
|
142
|
+
</div>
|
|
143
|
+
|
|
144
|
+
<hr />
|
|
145
|
+
|
|
146
|
+
<div style="margin-top: 20px">
|
|
147
|
+
<h3>Testes de :class e :style</h3>
|
|
148
|
+
<div
|
|
149
|
+
class="box"
|
|
150
|
+
:class="{ active }"
|
|
151
|
+
:style="{ backgroundColor: color, opacity: count ? 1 : 0.5 }"
|
|
152
|
+
>
|
|
153
|
+
Caixa de teste! Ativa: <strong :text="active"></strong>
|
|
154
|
+
</div>
|
|
155
|
+
|
|
156
|
+
<div style="margin-top: 10px">
|
|
157
|
+
<button @click="toggleActive">Alternar Classe 'active'</button>
|
|
158
|
+
|
|
159
|
+
<label style="margin-left: 10px">
|
|
160
|
+
Cor de Fundo:
|
|
161
|
+
<input type="color" :bind="color" />
|
|
162
|
+
</label>
|
|
163
|
+
</div>
|
|
164
|
+
</div>
|
|
165
|
+
|
|
166
|
+
<hr />
|
|
167
|
+
|
|
168
|
+
<div style="margin-top: 20px" @custom-event="handleCustomEvent">
|
|
169
|
+
<h3>Teste de $emit (Comunicação de Eventos)</h3>
|
|
170
|
+
<p>A div pai está escutando <code>@custom-event</code>.</p>
|
|
171
|
+
|
|
172
|
+
<!-- Escopo Filho Simulado -->
|
|
173
|
+
<div
|
|
174
|
+
:scope="{ component: 'Componente Interno' }"
|
|
175
|
+
style="
|
|
176
|
+
padding: 0 15px 15px 15px;
|
|
177
|
+
border: 2px dashed silver;
|
|
178
|
+
margin-top: 10px;
|
|
179
|
+
"
|
|
180
|
+
>
|
|
181
|
+
<p>Nome interno: <strong :text="component"></strong></p>
|
|
182
|
+
<button
|
|
183
|
+
@click="
|
|
184
|
+
$emit(
|
|
185
|
+
'custom-event',
|
|
186
|
+
{ message: `Mensagem enviada do ${component}` },
|
|
187
|
+
)
|
|
188
|
+
"
|
|
189
|
+
>
|
|
190
|
+
Disparar evento para o pai
|
|
191
|
+
</button>
|
|
192
|
+
</div>
|
|
193
|
+
</div>
|
|
194
|
+
</div>
|
|
195
|
+
</body>
|
|
196
|
+
</html>
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@jsweb/ui",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.3.0",
|
|
4
4
|
"description": "JS Web Microframework",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"js",
|
|
@@ -21,14 +21,30 @@
|
|
|
21
21
|
"license": "MIT",
|
|
22
22
|
"author": "Alex Bruno Cáceres <email@alexbruno.dev>",
|
|
23
23
|
"type": "module",
|
|
24
|
-
"main": "
|
|
25
|
-
"module": "
|
|
26
|
-
"types": "index.d.ts",
|
|
24
|
+
"main": "dist/ui.umd.js",
|
|
25
|
+
"module": "dist/ui.es.js",
|
|
26
|
+
"types": "dist/index.d.ts",
|
|
27
27
|
"exports": {
|
|
28
28
|
".": {
|
|
29
|
-
"import": "./
|
|
30
|
-
"require": "./
|
|
31
|
-
"types": "./index.d.ts"
|
|
29
|
+
"import": "./dist/ui.es.js",
|
|
30
|
+
"require": "./dist/ui.umd.js",
|
|
31
|
+
"types": "./dist/index.d.ts"
|
|
32
32
|
}
|
|
33
|
+
},
|
|
34
|
+
"scripts": {
|
|
35
|
+
"dev": "vite",
|
|
36
|
+
"build": "tsc && vite build && node publish.js",
|
|
37
|
+
"preview": "vite preview",
|
|
38
|
+
"format": "prettier --write .",
|
|
39
|
+
"test": "echo 'test'",
|
|
40
|
+
"preversion": "npm run build",
|
|
41
|
+
"postversion": "git push && git push --tags"
|
|
42
|
+
},
|
|
43
|
+
"devDependencies": {
|
|
44
|
+
"prettier": "^3.8.3",
|
|
45
|
+
"terser": "^5.46.2",
|
|
46
|
+
"typescript": "^6.0.3",
|
|
47
|
+
"vite": "^8.0.10",
|
|
48
|
+
"vite-plugin-dts": "^5.0.0"
|
|
33
49
|
}
|
|
34
|
-
}
|
|
50
|
+
}
|
package/publish.js
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { resolve } from 'node:path'
|
|
2
|
+
import { copyFileSync, readFileSync, writeFileSync } from 'node:fs'
|
|
3
|
+
|
|
4
|
+
const root = process.cwd()
|
|
5
|
+
const source = resolve(root, 'package.json')
|
|
6
|
+
const target = resolve(root, 'dist/package.json')
|
|
7
|
+
const pkgInfo = JSON.parse(readFileSync(source, 'utf8'))
|
|
8
|
+
|
|
9
|
+
// 1. Remove campos que não são necessários no pacote publicado
|
|
10
|
+
delete pkgInfo.scripts
|
|
11
|
+
delete pkgInfo.devDependencies
|
|
12
|
+
|
|
13
|
+
// 2. Ajusta os caminhos dos arquivos, pois o root do pacote agora será a pasta dist/
|
|
14
|
+
pkgInfo.main = 'index.umd.js'
|
|
15
|
+
pkgInfo.module = 'index.es.js'
|
|
16
|
+
pkgInfo.types = 'index.d.ts'
|
|
17
|
+
pkgInfo.exports = {
|
|
18
|
+
'.': {
|
|
19
|
+
import: './index.es.js',
|
|
20
|
+
require: './index.umd.js',
|
|
21
|
+
types: './index.d.ts',
|
|
22
|
+
},
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
// 3. Salva o package.json modificado dentro da pasta dist/
|
|
26
|
+
writeFileSync(target, JSON.stringify(pkgInfo, null, 2))
|
|
27
|
+
|
|
28
|
+
// 4. Copia arquivos de metadados importantes para o NPM
|
|
29
|
+
copyFileSync(resolve(root, 'README.md'), resolve(root, 'dist/README.md'))
|
|
30
|
+
copyFileSync(resolve(root, 'LICENSE'), resolve(root, 'dist/LICENSE'))
|
|
31
|
+
|
|
32
|
+
console.log(
|
|
33
|
+
'✅ Arquivo package.json mínimo e metadados preparados na pasta dist/',
|
|
34
|
+
)
|
package/src/evaluator.ts
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
export function evaluate(
|
|
2
|
+
expression: string,
|
|
3
|
+
context: Record<string, any> = {},
|
|
4
|
+
) {
|
|
5
|
+
try {
|
|
6
|
+
const fn = new Function(`with(this) { return ${expression} }`)
|
|
7
|
+
return fn.call(context)
|
|
8
|
+
} catch {
|
|
9
|
+
return undefined
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export function evaluateEvent(
|
|
14
|
+
$event: Event,
|
|
15
|
+
expression: string,
|
|
16
|
+
context: Record<string, any> = {},
|
|
17
|
+
) {
|
|
18
|
+
try {
|
|
19
|
+
const exp = expression.trim()
|
|
20
|
+
const isIdentifier = /^[a-zA-Z_$][0-9a-zA-Z_$.]*$/.test(exp)
|
|
21
|
+
const code = `${exp} instanceof Function ? ${exp}.call(this, $event) : ${exp}`
|
|
22
|
+
const result = isIdentifier ? code : exp
|
|
23
|
+
const fn = new Function('$event', `with(this) { ${result} }`)
|
|
24
|
+
|
|
25
|
+
fn.call(context, $event)
|
|
26
|
+
} catch {
|
|
27
|
+
console.warn(`[jsweb/ui] Error evaluating event: ${expression}`)
|
|
28
|
+
}
|
|
29
|
+
}
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { reactive, watch } from './reactivity'
|
|
2
|
+
import { createScope } from './parser'
|
|
3
|
+
|
|
4
|
+
export { reactive, watch, createScope }
|
|
5
|
+
|
|
6
|
+
if (typeof window !== 'undefined') {
|
|
7
|
+
const w = window as any
|
|
8
|
+
w.jsweb = w.jsweb || {}
|
|
9
|
+
w.jsweb.ui = { createScope, reactive, watch }
|
|
10
|
+
}
|