|
288 | 288 | [entity] |
289 | 289 | (or (:block/title entity) |
290 | 290 | (:block/name entity) |
| 291 | + (str (:logseq.property/value entity)) |
291 | 292 | "Untitled")) |
292 | 293 |
|
293 | 294 | (defn page-entity? |
|
312 | 313 | (coll? value) (empty? value) |
313 | 314 | :else false)) |
314 | 315 |
|
| 316 | +(defn format-datetime |
| 317 | + [value] |
| 318 | + (let [date (cond |
| 319 | + (instance? js/Date value) value |
| 320 | + (number? value) (js/Date. value) |
| 321 | + (string? value) (js/Date. value) |
| 322 | + :else nil)] |
| 323 | + (when date |
| 324 | + (-> (.toISOString date) |
| 325 | + (string/replace "T" " ") |
| 326 | + (string/replace "Z" ""))))) |
| 327 | + |
315 | 328 | (defn nodes-join |
316 | 329 | [nodes-list sep] |
317 | 330 | (reduce (fn [acc nodes] |
|
347 | 360 | [] |
348 | 361 |
|
349 | 362 | (string? value) |
350 | | - (content->nodes value (:uuid->title ctx) (:graph-uuid ctx)) |
| 363 | + (if (= prop-type :datetime) |
| 364 | + (if-let [formatted (format-datetime value)] |
| 365 | + [formatted] |
| 366 | + (content->nodes value (:uuid->title ctx) (:graph-uuid ctx))) |
| 367 | + (content->nodes value (:uuid->title ctx) (:graph-uuid ctx))) |
351 | 368 |
|
352 | 369 | (keyword? value) |
353 | 370 | [(name value)] |
354 | 371 |
|
355 | 372 | (map? value) |
356 | 373 | (if-let [eid (:db/id value)] |
357 | 374 | (property-value->nodes eid prop-key ctx entities) |
358 | | - [(pr-str value)]) |
| 375 | + (if-let [content (db-property/property-value-content value)] |
| 376 | + (property-value->nodes content prop-key ctx entities) |
| 377 | + [(pr-str value)])) |
359 | 378 |
|
360 | | - (set? value) |
361 | | - (nodes-join (map #(property-value->nodes % prop-key ctx entities) value) ", ") |
362 | | - |
363 | | - (sequential? value) |
| 379 | + (or (set? value) (sequential? value)) |
364 | 380 | (nodes-join (map #(property-value->nodes % prop-key ctx entities) value) ", ") |
365 | 381 |
|
366 | 382 | (number? value) |
367 | | - (if (and ref-type? (get entities value)) |
| 383 | + (cond |
| 384 | + (= prop-type :datetime) |
| 385 | + (if-let [formatted (format-datetime value)] |
| 386 | + [formatted] |
| 387 | + [(str value)]) |
| 388 | + |
| 389 | + (and ref-type? (get entities value)) |
368 | 390 | (entity->link-node (get entities value) ctx) |
| 391 | + |
| 392 | + :else |
369 | 393 | [(str value)]) |
370 | 394 |
|
371 | 395 | :else |
372 | 396 | [(str value)]))) |
373 | 397 |
|
374 | | -(defn entity-properties |
| 398 | +(defn built-in-tag? |
375 | 399 | [entity] |
| 400 | + (when-let [ident (:db/ident entity)] |
| 401 | + (= "logseq.class" (namespace ident)))) |
| 402 | + |
| 403 | +(defn filter-tags |
| 404 | + [values entities] |
| 405 | + (let [values (if (sequential? values) values [values])] |
| 406 | + (->> values |
| 407 | + (remove (fn [value] |
| 408 | + (cond |
| 409 | + (keyword? value) (= "logseq.class" (namespace value)) |
| 410 | + :else |
| 411 | + (let [entity (cond |
| 412 | + (map? value) value |
| 413 | + (number? value) (get entities value) |
| 414 | + :else nil)] |
| 415 | + (and entity (built-in-tag? entity)))))) |
| 416 | + vec))) |
| 417 | + |
| 418 | +(defn entity-properties |
| 419 | + [entity ctx entities] |
376 | 420 | (let [props (db-property/properties entity) |
377 | 421 | inline-props (:block/properties entity) |
378 | 422 | props (if (map? inline-props) |
379 | 423 | (merge props inline-props) |
380 | | - props)] |
381 | | - (into {} |
382 | | - (remove (fn [[_ v]] (property-value-empty? v))) |
383 | | - props))) |
| 424 | + props) |
| 425 | + props (->> props |
| 426 | + (remove (fn [[k _]] |
| 427 | + (true? (get (:property-hidden-by-ident ctx) k)))) |
| 428 | + (map (fn [[k v]] |
| 429 | + (if (= k :block/tags) |
| 430 | + [k (filter-tags v entities)] |
| 431 | + [k v]))) |
| 432 | + (remove (fn [[_ v]] (property-value-empty? v))) |
| 433 | + (remove (fn [[k v]] |
| 434 | + (and (= k :block/tags) (property-value-empty? v))))) |
| 435 | + props (into {} props)] |
| 436 | + props)) |
384 | 437 |
|
385 | 438 | (defn render-properties |
386 | 439 | [props ctx entities] |
|
604 | 657 | (let [child-id (:db/id block) |
605 | 658 | nested (render-block-tree children-by-parent child-id ctx) |
606 | 659 | has-children? (boolean nested) |
607 | | - properties (render-properties (entity-properties block) |
| 660 | + properties (render-properties (entity-properties block ctx (:entities ctx)) |
608 | 661 | ctx |
609 | 662 | (:entities ctx))] |
610 | 663 | [:li.block |
611 | 664 | [:div.block-content |
| 665 | + (block-content-nodes block ctx) |
612 | 666 | (when has-children? |
613 | 667 | [:button.block-toggle |
614 | 668 | {:type "button" :aria-expanded "true"} |
615 | | - "▾"]) |
616 | | - (block-content-nodes block ctx)] |
| 669 | + "▾"])] |
617 | 670 | (when properties |
618 | 671 | [:div.block-properties properties]) |
619 | 672 | (when nested |
|
668 | 721 | name->uuid (reduce (fn [acc [_e entity]] |
669 | 722 | (if-let [uuid-value (:block/uuid entity)] |
670 | 723 | (let [uuid-str (str uuid-value) |
671 | | - name (:block/name entity) |
672 | 724 | title (:block/title entity)] |
673 | | - (cond-> acc |
674 | | - name (assoc name uuid-str) |
675 | | - title (assoc title uuid-str) |
676 | | - title (assoc (common-util/page-name-sanity-lc title) uuid-str))) |
| 725 | + (assoc acc title uuid-str)) |
677 | 726 | acc)) |
678 | 727 | {} |
679 | 728 | entities) |
|
689 | 738 | acc)) |
690 | 739 | {} |
691 | 740 | entities) |
| 741 | + property-hidden-by-ident (reduce (fn [acc [_e entity]] |
| 742 | + (if-let [ident (:db/ident entity)] |
| 743 | + (assoc acc ident (true? (:logseq.property/hide? entity))) |
| 744 | + acc)) |
| 745 | + {} |
| 746 | + entities) |
692 | 747 | children-by-parent (->> entities |
693 | 748 | (reduce (fn [acc [e entity]] |
694 | 749 | (if (and (= (:block/page entity) page-eid) |
695 | | - (not= e page-eid)) |
| 750 | + (not= e page-eid) |
| 751 | + (not (:logseq.property/created-from-property entity))) |
696 | 752 | (let [parent (or (:block/parent entity) page-eid)] |
697 | 753 | (update acc parent (fnil conj []) entity)) |
698 | 754 | acc)) |
|
705 | 761 | :graph-uuid graph-uuid |
706 | 762 | :property-title-by-ident property-title-by-ident |
707 | 763 | :property-type-by-ident property-type-by-ident |
| 764 | + :property-hidden-by-ident property-hidden-by-ident |
708 | 765 | :entities entities} |
709 | | - page-properties (render-properties (entity-properties page-entity) |
| 766 | + page-properties (render-properties (entity-properties page-entity ctx entities) |
710 | 767 | ctx |
711 | 768 | entities) |
712 | 769 | blocks (render-block-tree children-by-parent page-eid ctx) |
|
744 | 801 | ".property-value{margin:0;color:#2e2a23;}" |
745 | 802 | ".block-properties{margin:6px 0 0 22px;}" |
746 | 803 | ".block-properties .properties{grid-template-columns:120px 1fr;font-size:13px;}" |
747 | | - ".block-toggle{border:none;background:transparent;cursor:pointer;font-size:14px;line-height:1;margin-top:3px;color:#6b7280;}" |
| 804 | + ".block-toggle{border:none;background:transparent;cursor:pointer;font-size:14px;line-height:1;margin-top:3px;margin-left:auto;color:#6b7280;}" |
748 | 805 | ".block.is-collapsed >.block-content >.block-toggle {transform: rotate(-90deg);}" |
749 | 806 | ".block-toggle:focus{outline:2px solid #c7b38f;outline-offset:2px;border-radius:4px;}" |
750 | 807 | ".block-children{margin-left:16px;}" |
|
797 | 854 | payload-entities) |
798 | 855 | page-title (when page-eid |
799 | 856 | (entity->title (get payload-entities page-eid))) |
800 | | - refs (when (and page-eid page-title) |
801 | | - (page-refs-from-payload payload page-eid page_uuid page-title graph))] |
| 857 | + refs (or (:refs payload) |
| 858 | + (get payload "refs") |
| 859 | + (when (and page-eid page-title) |
| 860 | + (page-refs-from-payload payload page-eid page_uuid page-title graph)))] |
802 | 861 | (cond |
803 | 862 | (not (valid-meta? meta)) |
804 | 863 | (bad-request "missing publish metadata") |
|
0 commit comments