From b7da7a19e98b80fdf044d3e910d866e464653b85 Mon Sep 17 00:00:00 2001 From: colin Date: Fri, 28 Jun 2024 23:00:16 -0700 Subject: reorg --- src/dom-transform.lisp | 9 ++++----- src/hypnotisml.lisp | 15 ++++++++++++--- src/package.lisp | 23 +++++++++++++++++++---- 3 files changed, 35 insertions(+), 12 deletions(-) diff --git a/src/dom-transform.lisp b/src/dom-transform.lisp index 803a7f4..0afe608 100644 --- a/src/dom-transform.lisp +++ b/src/dom-transform.lisp @@ -32,8 +32,7 @@ (defun empty-queue (q) (not (or (car q) (cdr q)))) -(defun ensure-parent (parent nodes) - (loop :for node :in nodes :do (setf (parent node) parent))) + (defun expand-walk (top node clauses) (a:with-gensyms (new-children frontier top-var parent) @@ -54,13 +53,13 @@ (:replace (push `(,guard (let ((,node ,phrase-body)) - (setf (parent ,node) ,parent) - (push ,node ,new-children))) + ;(setf (parent ,node) ,parent) + (pushnew ,node ,new-children :test #'eq))) conditional-exprs)) (:splice (push `(,guard (let ((,node ,phrase-body)) - (ensure-parent ,parent ,node) + ;(ensure-parent ,parent ,node) (setf ,new-children (nconc (reverse ,node) ,new-children)))) conditional-exprs)))))))) diff --git a/src/hypnotisml.lisp b/src/hypnotisml.lisp index ab06b6f..b70a8a8 100644 --- a/src/hypnotisml.lisp +++ b/src/hypnotisml.lisp @@ -89,12 +89,19 @@ (children :type node-list) :documentation "The base class for all UI elements.") +(defun ensure-parent (parent nodes) + (loop :for node :in nodes :do (setf (parent node) parent))) + (defmethod initialize-instance :around ((elem elem) &key) (call-next-method) - (loop :for child :in (children elem) - :do (setf (parent child) elem)) + (ensure-parent elem (children elem)) elem) +;; WARNING... THIS'LL SLOW YA DOWN +(defmethod (setf children) :after (new-children (elem elem)) + (ensure-parent elem new-children)) + + (defun elem-query-selector (elem) "Returns a CSS query selector string for the ELEM. ELEMs can be uniquely quried in the dom by passing string to .querySelector()" @@ -252,6 +259,8 @@ already present in the element." elem) + + ;;; RENDERING (defgeneric html (elem stream) @@ -567,7 +576,7 @@ E.g. :1/2, :1, :3/4" (defmacro (&rest content-specs) `(
($ :display "grid") - ,@(loop :for (row col content) :in content-specs + ,@(loop :for ((row col) content . _) :on content-specs :by #'cddr :unless (and (rational-name-p row) (rational-name-p col)) :do (error "Bad thing to be a grid content spec: ~s" diff --git a/src/package.lisp b/src/package.lisp index c811dad..5743aa3 100644 --- a/src/package.lisp +++ b/src/package.lisp @@ -4,6 +4,13 @@ (:use #:cl) (:local-nicknames (#:a #:alexandria)) + + ;; general + (:export + #:elemp + #:elem-tag + #:parent) + ;; Core Html Elements (:export #: @@ -140,7 +147,9 @@ ;; layout constructors (:export #: - #:) + #: + #: + #:defgrid) ;; element properties (:export @@ -153,10 +162,16 @@ #:$~ #:$?) - ;; parenscript macros + ;; styling helpers (:export - #:$$ - #:$$replace) + #:$center + #:$vcenter + #:$hcenter) + + ;; parenscript macros + ;; (:export + ;; #:$$ + ;; #:$$replace) ;; transforms and structure editing (:export -- cgit v1.2.3