Skip to content

Commit

Permalink
fix: added header for seo
Browse files Browse the repository at this point in the history
  • Loading branch information
frankpagan committed Jun 16, 2021
1 parent 0a4bc3d commit c348f32
Show file tree
Hide file tree
Showing 8 changed files with 89 additions and 39 deletions.
2 changes: 1 addition & 1 deletion demo/components/block-form.html
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@
<cocreate-select class="floating-label" name="category" placeholder="Category-select">
<input class="text">
<ul class="display:flex flex-direction:column background:whitesmoke width:100%" data-fetch_collection="tags" data-template_id="categories">
<cc-option class="template" data-template_id="categories" data-collection="{{collection}}" data-document_id="{{data._id}}" name="name">Layout</cc-option>
<cc-option class="template" data-template_id="categories" data-document_id="{{data._id}}"><span data-collection="{{collection}}" data-document_id="{{data._id}}" name="name">layout</span></cc-options>
</ul>
</cocreate-select>
<!--<select class="floating-label" name="category" placeholder="Category">-->
Expand Down
2 changes: 1 addition & 1 deletion demo/components/code-editor.html
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,6 @@
</script>
<!--<script src="https://cdn.cocreate.app/latest/CoCreate.min.js" ></script>-->
<script src="https://server.cocreate.app/CoCreateJS/dist/CoCreate.js"></script>
<script src="https://server.cocreate.app/CoCreate-plugins/CoCreate-codemirror/dist/demo.js"></script>
<!--<script src="https://server.cocreate.app/CoCreate-plugins/CoCreate-codemirror/dist/demo.js"></script>-->

</html>
2 changes: 1 addition & 1 deletion docs/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ <h2>CoCreate-builder</h2>
<a href="https://github.com/CoCreate-app/CoCreate-builder" target="_blank" class="margin-right:15px"><i class="fab fa-github"></i></a>
</div>
</div>
<p class="max-width:500px margin:20px_10px line-height:1.5">A simple HTML5, CSS and pure javascript component. Easy configuration using data-attributes and highly styleable.</p>
<h1 class="max-width:500px margin:20px_10px line-height:1.5 font-size:16px font-weight:100">A simple HTML5, CSS and pure javascript component. Easy configuration using data-attributes and highly styleable.</h1>
<div id="builder-section" class="display:flex flex-wrap:wrap">
<div class="flex-grow:1 width:400px width:300px@xs padding:0px_10px margin-top:60px">

Expand Down
43 changes: 27 additions & 16 deletions src/components/contentEditable.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,39 +4,50 @@

export default resolveCanvas.then(async function({ crdtCon, weirdCrdtCon, canvas, canvasDocument, canvasWindow }) {
const domTexti = await domText;

// ***
// let contenteditableImport = await import('@cocreate/contenteditable');
// let contenteditable = contenteditableImport.default;
// // *** is the same as
// import('@cocreate/contenteditable').then(({contenteditable})=>{


// })
// //*** is the same as non-lazy load version of import which will not work in here! just for the reference
// import contenteditable from "@cocreate/contenteditable";
//***


// g_CoCreateContentEditable()
canvasDocument.addEventListener('dblclick', (e) => {



let element = e.target;
if(element.hasAttribute('contenteditable'))
return;

let vv = element.innerText;

let id = element.getAttribute('data-element_id');
element.setAttribute('contenteditable', true);
element.addEventListener('input', () => {
// if (!element.hasAttribute('name') || !element.hasAttribute('data-collection') || !element.hasAttribute('data-document_id'))
domTexti.setInnerText({ target: id, value: element.innerText, avoidTextToDom: true })
})

let vv = element.innerText;
element.setAttribute('data-realtime', true)
console.log("hereeeeeeeeeeeeeeee", weirdCrdtCon)
element.setAttribute('name', `innertext-${id}`)
element.setAttribute('data-collection', `builder`)
element.setAttribute('data-document_id', `null`);




element.setAttribute('data-collection', weirdCrdtCon.collection)
element.setAttribute('data-document_id', weirdCrdtCon.document_id);

setTimeout(() => {
if ((crdt.getText(weirdCrdtCon) || !element.innerText ) && (!crdt.getText(weirdCrdtCon) || element.innerText ) )
crdt.replaceText({
crud: false,
...weirdCrdtCon,
value: vv,
});


}, 0)

element.addEventListener('input', () => {
// if (!element.hasAttribute('name') || !element.hasAttribute('data-collection') || !element.hasAttribute('data-document_id'))
domTexti.setInnerText({ target: id, value: element.innerText, avoidTextToDom: true })
})

})
})
Expand Down
3 changes: 2 additions & 1 deletion src/components/initDnd.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ export default resolveCanvas.then(async function({ crdtCon, canvas, canvasDocume
position,
target: dropedEl.getAttribute("data-element_id"),
element: dragedEl.getAttribute("data-element_id"),

metadata: { type: 'dnd' }
});

break;
Expand All @@ -47,6 +47,7 @@ export default resolveCanvas.then(async function({ crdtCon, canvas, canvasDocume
position,
target: dropedEl.getAttribute("data-element_id"),
elementValue: dragedEl.outerHTML,
metadata: { type: 'dnd' }
});
break;
}
Expand Down
36 changes: 25 additions & 11 deletions src/components/initDomText.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
let domTexti = new domText(html, canvasDocument.documentElement)
// window.insertTextList = [];
domTexti.setCallback({
addCallback: function({ value, position, avoidTextToDom = 'fff'}) {
addCallback: function({ value, position, avoidTextToDom = false }) {
let html = crdt.getText({ crud: false, ...crdtCon })
// if (html)
// window.insertTextList.push({
Expand All @@ -30,19 +30,19 @@
// else
// window.insertTextList.push({ value, position, virtual: 'crdt.getText returned nothing' })
CoCreate.crdt.insertText({
attributes: { avoidTextToDom },
// attributes: { avoidTextToDom },
crud: false,
...crdtCon,
value,
position,
});
},
removeCallback: function({ from, to, avoidTextToDom = 'fff' }) {
removeCallback: function({ from, to, avoidTextToDom = false }) {



CoCreate.crdt.deleteText({
attributes: { avoidTextToDom },
// attributes: { avoidTextToDom },
crud: false,
...crdtCon,
position: from,
Expand All @@ -55,28 +55,42 @@
try {
let detail = event.detail;

let { avoidTextToDom } = e.detail;
if (avoidTextToDom && detail['collection'] && detail['name'] && detail['document_id'])
return;
// let { avoidTextToDom } = e.detail;
// if (avoidTextToDom && detail['collection'] && detail['name'] && detail['document_id'])
// return;


console.log('eee>>>>', event)
if (detail['collection'] !== crdtCon['collection'] || detail['name'] !== crdtCon['name'] || detail['document_id'] !== crdtCon['document_id'])
return;




// sleep(200)
let eventDelta = detail.eventDelta;

for (let i = 0; i < eventDelta.length; i++) {

if (eventDelta[i]?.attributes?.avoidTextToDom)
return;
}
let html = crdt.getText(crdtCon);
domTextiTextToDom.html = domTexti.html = html;

let eventDelta = detail.eventDelta;

if (!window.savedDelta)
window.savedDelta = []
else
window.savedDelta.push(eventDelta)
// if(!info[1]) return;




let pos = 0;
for (let i = 0; i < eventDelta.length; i++) {

if (eventDelta[i].retain)
pos = eventDelta[i].retain;
else {
Expand Down
26 changes: 21 additions & 5 deletions src/components/resolveCanvas.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,16 +53,29 @@
crdt.init(crdtCon);


function weirdCrdtInit(crdtCon, crdt) {
function weirdCrdtInit(crdtCon, crdt, doc) {
let newCrdtCon = Object.assign({}, crdtCon);

newCrdtCon.collection = newCrdtCon.document_id;
newCrdtCon.document_id = 'null';
delete newCrdtCon.name;
// delete newCrdtCon.name;
crdt.init(newCrdtCon);

let el = doc.createElement('div')
el.setAttribute('contenteditable', '')
el.style.display = 'none';
el.setAttribute('data-document_id', newCrdtCon.document_id)
el.setAttribute('data-collection', newCrdtCon.collection)
el.setAttribute('name', newCrdtCon.name);
doc.body.appendChild(el);




return newCrdtCon
}
let weirdCrdtCon = weirdCrdtInit(crdtCon, crdt)
let weirdCrdtCon = weirdCrdtInit(crdtCon, crdt, document)


export default new Promise(async function(resolve, reject) {

Expand Down Expand Up @@ -106,7 +119,9 @@
newIframe.srcdoc = html;

// canvas.appendChild(canvasDocument);

// let script = document.createElement('script');
// script.setAttribute('src', 'cc-contenteditable/dist/index.js')
// document.appendChild(script);

for (let att of canvas.attributes) {
newIframe.setAttribute(att.name, att.value);
Expand All @@ -118,8 +133,9 @@
canvasWindow = newIframe.contentWindow;
canvasDocument = canvasWindow.document || newIframe.contentDocument;
canvasDocument.ccdefaultView = canvasWindow;

let weirdCrdtCon = weirdCrdtInit(crdtCon, canvasWindow.CoCreate.crdt, canvasDocument);
resolve({ crdtCon, weirdCrdtCon, canvas: newIframe, canvasDocument, canvasWindow })
weirdCrdtInit(crdtCon, canvasWindow.CoCreate.crdt)
})


Expand Down
14 changes: 11 additions & 3 deletions test/text-to-dom/all-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,17 @@
// drag and drop crdt text test

// init crdt
// CoCreate.crdt.init({collection: "apples",
// document_id: "60a59d2ea8e31d7406d05bdb",
// name: "html"});
/*
CoCreate.crdt.init({
collection: "apples",
document_id: "60bfee00e1aabf0011a15c54",
name: "html"});
CoCreate.crdt.init({
collection: "60bfee00e1aabf0011a15c54",
document_id: "null",
name: "html"});
*/

// drag element 3
CoCreate.crdt.deleteText({collection: "apples",
Expand Down

0 comments on commit c348f32

Please sign in to comment.