@-0/browser
Advanced tools
Comparing version 0.2.96 to 0.2.97
import { URL_DATA, CMD_SUB$, CMD_ARGS, CMD_WORK, DOM_HEAD } from "@-0/keys"; | ||
import { registerCMD } from "@-0/spool"; | ||
const setFavicon = (href) => { | ||
const setFavicon = href => { | ||
let link = document.querySelector("link[rel*='icon']") || document.createElement("link"); | ||
@@ -10,13 +10,16 @@ link.type = "image/x-icon"; | ||
}; | ||
const meta = prop => (document.head.querySelector(`meta[property="${prop}"]`) && | ||
document.head.querySelector(`meta[property="${prop}"]`).content) || | ||
null; | ||
const defalt_cfg = { | ||
meta: { | ||
"og:title": document.title, | ||
"og:image": document.head.querySelector(`meta[property="og:image"]`).content, | ||
"og:image:width": document.head.querySelector(`meta[property="og:image:width"]`).content, | ||
"og:image:height": document.head.querySelector(`meta[property="og:image:height"]`).content, | ||
"og:description": document.head.querySelector(`meta[property="og:description"]`).content, | ||
"og:type": document.head.querySelector(`meta[property="og:image"]`).content, | ||
"og:image": meta("og:image"), | ||
"og:image:width": meta("og:image:width"), | ||
"og:image:height": meta("og:image:height"), | ||
"og:description": meta("og:description"), | ||
"og:type": meta("og:type") | ||
}, | ||
title: document.title, | ||
favicon: document.querySelector("link[rel*='icon']"), | ||
favicon: document.querySelector("link[rel*='icon']") | ||
}; | ||
@@ -35,3 +38,3 @@ const replaceMeta = (obj = defalt_cfg) => { | ||
}, | ||
HEAD_favicon: () => setFavicon(val), | ||
HEAD_favicon: () => setFavicon(val) | ||
}[key](); | ||
@@ -44,3 +47,3 @@ } | ||
}; | ||
const conformToHead = ({ title = defalt_cfg.title, description = defalt_cfg.meta["og:description"], img_url = defalt_cfg.meta["og:image"], img_height = defalt_cfg.meta["og:image:height"], img_width = defalt_cfg.meta["og:image:width"], favicon = defalt_cfg.favicon, type = defalt_cfg.meta["og:type"], }) => ({ | ||
const conformToHead = ({ title = defalt_cfg.title, description = defalt_cfg.meta["og:description"], img_url = defalt_cfg.meta["og:image"], img_height = defalt_cfg.meta["og:image:height"], img_width = defalt_cfg.meta["og:image:width"], favicon = defalt_cfg.favicon, type = defalt_cfg.meta["og:type"] }) => ({ | ||
HEAD_meta: { | ||
@@ -52,11 +55,11 @@ "og:title": title, | ||
"og:image:height": img_height, | ||
"og:image": img_url, | ||
"og:image": img_url | ||
}, | ||
HEAD_title: title, | ||
HEAD_favicon: favicon, | ||
HEAD_favicon: favicon | ||
}); | ||
export const INJECT_HEAD = registerCMD({ | ||
[CMD_SUB$]: "_INJECT_HEAD", | ||
[CMD_ARGS]: (acc) => ({ [URL_DATA]: acc[URL_DATA] }), | ||
[CMD_WORK]: ({ [URL_DATA]: { [DOM_HEAD]: { title, description, img_url, img_height, img_width, favicon, type }, }, }) => replaceMeta(conformToHead({ title, description, img_url, img_height, img_width, favicon, type })), | ||
[CMD_ARGS]: acc => ({ [URL_DATA]: acc[URL_DATA] }), | ||
[CMD_WORK]: ({ [URL_DATA]: { [DOM_HEAD]: { title, description, img_url, img_height, img_width, favicon, type } } }) => replaceMeta(conformToHead({ title, description, img_url, img_height, img_width, favicon, type })) | ||
}); |
@@ -1,2 +0,2 @@ | ||
import { URL2obj } from "@-0/utils"; | ||
import { URL2obj, Err_missing_props } from "@-0/utils"; | ||
import { DOM_NODE, URL_FULL, URL_PATH, CMD_SUB$, CMD_ARGS, CMD_WORK } from "@-0/keys"; | ||
@@ -24,8 +24,10 @@ import { registerCMD } from "@-0/spool"; | ||
const setLinkAttrs = target => { | ||
document.body.querySelectorAll("a[visited]").forEach((el) => { | ||
if (el.href === window.location.href) | ||
el.setAttribute("active", ""); | ||
else | ||
el.removeAttribute("active"); | ||
}); | ||
document && | ||
document.body && | ||
document.body.querySelectorAll("a[visited]").forEach((el) => { | ||
if (el.href === window.location.href) | ||
el.setAttribute("active", ""); | ||
else | ||
el.removeAttribute("active"); | ||
}); | ||
if (target.setAttribute) { | ||
@@ -38,11 +40,13 @@ target.setAttribute("visited", ""); | ||
[CMD_SUB$]: "_SET_LINK_ATTRS_DOM", | ||
[CMD_ARGS]: acc => ({ [DOM_NODE]: acc[DOM_NODE] }), | ||
[CMD_WORK]: args => setLinkAttrs(args[DOM_NODE]) | ||
[CMD_ARGS]: ({ [DOM_NODE]: NODE }) => ({ [DOM_NODE]: NODE }), | ||
[CMD_WORK]: ({ [DOM_NODE]: NODE }) => { | ||
if (NODE) | ||
return setLinkAttrs(NODE); | ||
console.warn(Err_missing_props("SET_LINK_ATTRS_DOM", NODE)); | ||
} | ||
}); | ||
export const HREF_PUSHSTATE_DOM = registerCMD({ | ||
[CMD_SUB$]: "_HREF_PUSHSTATE_DOM", | ||
[CMD_ARGS]: acc => ({ [URL_FULL]: acc[URL_FULL], [DOM_NODE]: acc[DOM_NODE] }), | ||
[CMD_WORK]: args => !args[DOM_NODE].document | ||
? history.pushState(URL2obj(args[URL_FULL]), null, args[URL_FULL]) | ||
: null | ||
[CMD_ARGS]: ({ [URL_FULL]: URL, [DOM_NODE]: NODE }) => ({ [URL_FULL]: URL, [DOM_NODE]: NODE }), | ||
[CMD_WORK]: ({ [URL_FULL]: URL, [DOM_NODE]: NODE }) => NODE && !NODE.document ? history.pushState(URL2obj(URL), null, URL) : null | ||
}); | ||
@@ -52,3 +56,3 @@ export const NOTIFY_PRERENDER_DOM = registerCMD({ | ||
[CMD_ARGS]: true, | ||
[CMD_WORK]: () => document.dispatchEvent(new Event("rendered")) | ||
[CMD_WORK]: () => document && document.dispatchEvent(new Event("rendered")) | ||
}); |
@@ -1,2 +0,1 @@ | ||
export { registerRouterDOM } from "../registers"; | ||
export { DOMnavigated$, DOMContentLoaded$, popstate$ } from "./stream$"; |
@@ -1,2 +0,1 @@ | ||
export { registerRouterDOM } from "../registers"; | ||
export { DOMnavigated$, DOMContentLoaded$, popstate$ } from "./stream$"; |
export { FLIP_FIRST, FLIP_LAST_INVERSE_PLAY, INJECT_HEAD, HURL, HURLer } from "./commands"; | ||
export { registerRouterDOM, DOMnavigated$ } from "./core"; | ||
export { DOMnavigated$ } from "./core"; | ||
export { registerRouterDOM } from "./registers"; | ||
export { URL_DOM__ROUTE } from "./tasks"; | ||
export { $store$, set$$tate } from "./store"; |
export { FLIP_FIRST, FLIP_LAST_INVERSE_PLAY, INJECT_HEAD, HURL, HURLer } from "./commands"; | ||
export { registerRouterDOM, DOMnavigated$ } from "./core"; | ||
export { DOMnavigated$ } from "./core"; | ||
export { registerRouterDOM } from "./registers"; | ||
export { URL_DOM__ROUTE } from "./tasks"; | ||
export { $store$, set$$tate } from "./store"; |
@@ -1,2 +0,1 @@ | ||
import { Command } from "@-0/keys"; | ||
export declare const registerRouterDOM: (router: any) => Command; | ||
export { registerRouterDOM } from "./routing"; |
@@ -1,14 +0,1 @@ | ||
import { DOM_NODE, URL_FULL, CMD_SUB$, CMD_ARGS, CMD_SRC$, CMD_WORK } from "@-0/keys"; | ||
import { run$, registerCMD } from "@-0/spool"; | ||
import { URL_DOM__ROUTE } from "../tasks"; | ||
import { DOMnavigated$ } from "../core/stream$"; | ||
export const registerRouterDOM = (router) => { | ||
console.log("DOM Router Registered"); | ||
const task = URL_DOM__ROUTE(router); | ||
return registerCMD({ | ||
[CMD_SRC$]: DOMnavigated$, | ||
[CMD_SUB$]: "_URL_NAVIGATED$_DOM", | ||
[CMD_ARGS]: x => x, | ||
[CMD_WORK]: args => run$.next(task({ [URL_FULL]: args[URL_FULL], [DOM_NODE]: args[DOM_NODE] })) | ||
}); | ||
}; | ||
export { registerRouterDOM } from "./routing"; |
@@ -30,4 +30,4 @@ import { isObject } from "@thi.ng/checks"; | ||
[CMD_RESO]: (_acc, _res) => ({ | ||
[URL_PAGE]: _res[URL_PAGE], | ||
[URL_DATA]: _res[URL_DATA] | ||
[URL_PAGE]: (_res && _res[URL_PAGE]) || null, | ||
[URL_DATA]: (_res && _res[URL_DATA]) || null | ||
}), | ||
@@ -58,7 +58,7 @@ [CMD_ERRO]: (_acc, _err) => console.warn("Error in URL__ROUTE:", _err, "constructed:", _acc) | ||
[STATE_PATH]: [$$_VIEW], | ||
[STATE_DATA]: _acc[URL_PAGE] | ||
[STATE_DATA]: _acc[URL_PAGE] || null | ||
}) }), | ||
Object.assign(Object.assign({}, SET_STATE), { [CMD_ARGS]: _acc => ({ | ||
[STATE_PATH]: _acc[URL_PATH], | ||
[STATE_DATA]: _acc[URL_DATA][DOM_BODY] || _acc[URL_DATA] | ||
[STATE_DATA]: (_acc[URL_DATA] && _acc[URL_DATA][DOM_BODY]) || _acc[URL_DATA] | ||
}) }), | ||
@@ -65,0 +65,0 @@ SET_LINK_ATTRS_DOM, |
@@ -5,3 +5,3 @@ { | ||
"license": "MIT", | ||
"version": "0.2.96", | ||
"version": "0.2.97", | ||
"description": "Browser helpers for -0 state management, routing and the interaction between", | ||
@@ -44,5 +44,5 @@ "main": "./lib/index.js", | ||
"dependencies": { | ||
"@-0/keys": "^0.2.92", | ||
"@-0/utils": "^0.2.92", | ||
"@-0/spool": "^0.2.100" | ||
"@-0/keys": "^0.2.95", | ||
"@-0/utils": "^0.2.93", | ||
"@-0/spool": "^0.2.101" | ||
}, | ||
@@ -60,4 +60,4 @@ "devDependencies": { | ||
"@types/node": "^14.14.25", | ||
"@typescript-eslint/eslint-plugin": "^4.14.2", | ||
"@typescript-eslint/parser": "^4.14.2", | ||
"@typescript-eslint/eslint-plugin": "^4.15.0", | ||
"@typescript-eslint/parser": "^4.15.0", | ||
"babel-jest": "^26.6.3", | ||
@@ -70,11 +70,13 @@ "better-docs": "^2.3.2", | ||
"prettier": "^2.2.1", | ||
"ts-jest": "^26.5.0" | ||
"ts-jest": "^26.5.1", | ||
"typescript": "^4.1.5" | ||
}, | ||
"prettier": { | ||
"singleQuote": false, | ||
"printWidth": 100, | ||
"printWidth": 120, | ||
"endOfLine": "lf", | ||
"tabWidth": 2, | ||
"semi": false | ||
"tabWidth": 4, | ||
"semi": false, | ||
"arrowParens": "avoid" | ||
} | ||
} |
41851
32
423
21
Updated@-0/keys@^0.2.95
Updated@-0/spool@^0.2.101
Updated@-0/utils@^0.2.93