Skip to content

Commit a87fc39

Browse files
committed
Merge branch 'dev'
2 parents 658598e + 8e7c15d commit a87fc39

File tree

3 files changed

+27
-24
lines changed

3 files changed

+27
-24
lines changed

src/fetchSrc.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { getRelativePath, ObjectId } from "@cocreate/utils";
33

44
const selector =
55
"[src]:not(img, video, audio, script, input, iframe, frame, link, source), [source], [stream]";
6-
const initializing = new Map();
6+
const textExtensions = ['html','htm','xhtml','css','js','mjs','cjs','json','jsonc','json5','xml','xsd','xsl','xslt','svg','md','markdown','scss','sass','less','vue','jsx','tsx','graphql','gql','htc','webmanifest','txt','csv','tsv','yaml','yml','toml','ini','log','dat','env','c','cc','cpp','cxx','h','hh','hpp','hxx','m','mm','cs','java','jsp','properties','py','pyc','pyd','pyo','rb','erb','php','phtml','php3','php4','php5','php7','phps','go','rs','swift','kt','kts','ts','pl','pm','pod','sh','bash','zsh','ksh','csh','tcsh','ps1','psm1','psd1','bat','cmd','sql','r','Rprofile','Rmd','lua','hs','lhs','erl','hrl','scala','sbt','d','f','for','f77','f90','f95','f03','f08','adb','ads','cbl','cob','cpy','lisp','lsp','scm','ss','pro','plg','vb','vbs','dart','asm','s','conf','cfg','config','ini','env','npmrc','yarnrc','gitattributes','gitignore','gitmodules','gitkeep','editorconfig','prettierrc','eslintrc','eslintignore','browserslistrc','package.json','package-lock.json','tsconfig.json','babelrc','vite.config.js','rollup.config.js','webpack.config.js','procfile','dockerfile','dockerignore','makefile','gradle','groovy','pom','properties','service','target','rst','adoc','asciidoc','tex','latex','textile','org','wiki','nfo','rtf','gcode','patch','diff','log','reg','map','sub','srt','dic','wml','rss','atom','gpx','kml','kmz','vcf','vcard','ics','ical','ps','eps','mf','lic','license','pem','key','crt','cert','pub','tpl','liquid','mustache','hbs','twig','blade.php','ejs','coffee','litcoffee','jl','nim','zig','wgsl']; const initializing = new Map();
77

88
function init(elements) {
99
if (elements && !Array.isArray(elements)) elements = [elements];
@@ -37,6 +37,7 @@ async function initElements(elements) {
3737
if (element.tagName === "AUDIO" || element.tagName === "VIDEO") {
3838
initMediaSource(element, src);
3939
} else {
40+
if (src && !textExtensions.includes(src.split('.').pop())) return
4041
element.removeAttribute("rendered");
4142

4243
let text = await response.text();

src/form.js

Lines changed: 23 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -54,29 +54,32 @@ function runObjectId(form) {
5454
}
5555
}
5656

57+
const formAttributes = [
58+
"organization_id",
59+
"host",
60+
"storage",
61+
"database",
62+
"array",
63+
"index",
64+
"object",
65+
"key"
66+
];
67+
const formAttributesSelector = formAttributes.map((attr) => `[${attr}]`).join(", ");
68+
5769
/**
5870
* @param form
5971
*/
6072
function setAttribute(form, elements) {
61-
if (!elements)
62-
elements = form.querySelectorAll(
63-
"[organization_id], [host], [storage], [database], [array], [index], [object], [key]"
64-
);
73+
if (!elements) elements = form.querySelectorAll(formAttributesSelector);
6574

6675
for (let attribute of form.attributes) {
67-
let variable = window.CoCreateConfig.attributes[attribute.name];
68-
69-
// Set the attribute of all elements in the variable
70-
if (variable) {
71-
for (let el of elements) {
72-
// Set the value of the attribute.
73-
// TODO: skip-attribute naming convention, perhaps skip by defualt if storage, database, array not the same and use attribute to apply for cases where one _id will be used across 2 arrays
74-
if (
75-
!el.getAttribute(attribute.name) &&
76-
!el.hasAttribute("skip-attribute")
77-
) {
78-
el.setAttribute(attribute.name, attribute.value);
79-
}
76+
if (!formAttributes.includes(attribute.name)) continue;
77+
78+
for (let el of elements) {
79+
// Set the value of the attribute.
80+
// TODO: skip-attribute naming convention, perhaps skip by defualt if storage, database, array not the same and use attribute to apply for cases where one _id will be used across 2 arrays
81+
if ( !el.hasAttribute("skip-attribute") ) {
82+
el.setAttribute(attribute.name, attribute.value);
8083
}
8184
}
8285
}
@@ -208,11 +211,10 @@ Observer.init({
208211
Observer.init({
209212
name: "CoCreateFormElements",
210213
types: ["addedNodes"],
211-
selector:
212-
"[organization_id], [host], [storage], [database], [array], [index], [object], [key]",
214+
selector: formAttributesSelector,
213215
callback: function (mutation) {
214-
if (mutation.target.form)
215-
setAttribute(mutation.target.form, [mutation.target]);
216+
let form = mutation.target.form || mutation.target.closest("form");
217+
if (form) setAttribute(form, [mutation.target]);
216218
}
217219
});
218220

src/index.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ async function initElement(el) {
123123
["INPUT", "TEXTAREA", "SELECT"].includes(el.tagName) ||
124124
(el.hasAttribute("contenteditable") &&
125125
el.getAttribute("contenteditable") !== "false") ||
126-
el.contenteditable
126+
el.contenteditable || el.value !== undefined || el.hasAttribute("value")
127127
) {
128128
if (el.tagName == "IFRAME") {
129129
// ToDo: saving on contenteditable elements when an objectId does not exist in order to crud or crdt
@@ -143,7 +143,7 @@ async function initElement(el) {
143143
if (e.detail && e.detail.skip == true) return;
144144
if (data.type !== "object" && data[data.type] === "pending")
145145
return;
146-
146+
if (!el.value && !el.hasAttribute("value") && el.contenteditable && !el.hasAttribute("contenteditable")) return;
147147
save(el);
148148
});
149149
}

0 commit comments

Comments
 (0)