mirror of
https://github.com/flynx/pWiki.git
synced 2025-12-25 20:31:58 +00:00
Compare commits
No commits in common. "78af3300c215f2cb7f8e9d33e5c1826c1cd7c322" and "e39bab97e04ab9c887a512446c5968391adbf4fd" have entirely different histories.
78af3300c2
...
e39bab97e0
@ -203,14 +203,15 @@ var plugin = {
|
|||||||
var attributes = {
|
var attributes = {
|
||||||
__proto__: plugin,
|
__proto__: plugin,
|
||||||
|
|
||||||
// XXX should attr settings be set here or in the Outline???
|
|
||||||
// ...this includes .__block_attrs__ and .__system_attrs__
|
|
||||||
|
|
||||||
//
|
//
|
||||||
// Parse attrs...
|
// Parse attrs...
|
||||||
// .parseBlockAttrs(<text>[, <elem>])
|
// .parseBlockAttrs(<text>[, <elem>])
|
||||||
// -> [<elem>, <attrs>, <sys-attrs>]
|
// -> [<elem>, <attrs>, <sys-attrs>]
|
||||||
//
|
//
|
||||||
|
// XXX where should we get .__block_attrs__???
|
||||||
|
// ...editor (current), plugin, ...???
|
||||||
|
// XXX might be a good idea to split out the actual code handler to
|
||||||
|
// be overloadable by other plugins...
|
||||||
parseBlockAttrs: function(editor, text, elem={}){
|
parseBlockAttrs: function(editor, text, elem={}){
|
||||||
var system = editor.__block_attrs__
|
var system = editor.__block_attrs__
|
||||||
var attrs = ''
|
var attrs = ''
|
||||||
@ -228,29 +229,18 @@ var attributes = {
|
|||||||
.split(/(?:[\t ]*::[\t ]*|[\t ]*\n[\t ]*)/g)
|
.split(/(?:[\t ]*::[\t ]*|[\t ]*\n[\t ]*)/g)
|
||||||
while(match.length > 0){
|
while(match.length > 0){
|
||||||
var [name, val] = match.splice(0, 2)
|
var [name, val] = match.splice(0, 2)
|
||||||
// ignore non-settable attrs...
|
|
||||||
if(editor.__system_attrs__.includes(name)){
|
|
||||||
continue }
|
|
||||||
elem[name] =
|
elem[name] =
|
||||||
val == 'true' ?
|
val == 'true' ?
|
||||||
true
|
true
|
||||||
: val == 'false' ?
|
: val == 'false' ?
|
||||||
false
|
false
|
||||||
: val }
|
: val
|
||||||
return ws })
|
// keep non-system attrs...
|
||||||
// build the attr strings...
|
|
||||||
// NOTE: we are not doing this in the loop above to include all
|
|
||||||
// the attributes that are in the elem but not explicitly
|
|
||||||
// given in code...
|
|
||||||
for(var name in elem){
|
|
||||||
// ignore non-settable attrs...
|
|
||||||
if(editor.__system_attrs__.includes(name)){
|
|
||||||
continue }
|
|
||||||
var val = elem[name]
|
|
||||||
if(!(name in system)){
|
if(!(name in system)){
|
||||||
attrs += `\n${name}::${val}`
|
attrs += `\n${name}::${val}`
|
||||||
} else {
|
} else {
|
||||||
sysattrs += `\n${name}::${val}` } }
|
sysattrs += `\n${name}::${val}` } }
|
||||||
|
return ws })
|
||||||
return [
|
return [
|
||||||
elem,
|
elem,
|
||||||
attrs,
|
attrs,
|
||||||
@ -258,46 +248,26 @@ var attributes = {
|
|||||||
] },
|
] },
|
||||||
|
|
||||||
// generate code...
|
// generate code...
|
||||||
//
|
|
||||||
// this is controlled by the value of editor.__code_attrs__:
|
|
||||||
// false / undefined - strip attrs
|
|
||||||
// true - add attrs to code if available
|
|
||||||
// 'all' - add attrs, including system attrs to
|
|
||||||
// code if available,
|
|
||||||
__parse_code__: function(code, editor, elem){
|
__parse_code__: function(code, editor, elem){
|
||||||
var [elem, attrs, system] = this.parseBlockAttrs(editor, code, elem)
|
var [elem, attrs, system] = this.parseBlockAttrs(editor, code, elem)
|
||||||
return !editor.__code_attrs__ ?
|
return !editor.__code_attrs__ ?
|
||||||
elem.text
|
elem.text
|
||||||
: editor.__code_attrs__ == 'all' ?
|
: editor.__code_attrs__ == 'all' ?
|
||||||
elem.text
|
elem.text +'\n'+ attrs +'\n'+ system
|
||||||
+ (attrs.length > 0 ?
|
: elem.text +'\n'+ attrs },
|
||||||
'\n'+ attrs
|
|
||||||
: '')
|
|
||||||
+ (system.length > 0 ?
|
|
||||||
'\n'+ system
|
|
||||||
: '')
|
|
||||||
: attrs.length > 0 ?
|
|
||||||
elem.text +'\n'+ attrs
|
|
||||||
: elem.text },
|
|
||||||
|
|
||||||
// generate view...
|
// generate view...
|
||||||
//
|
|
||||||
// this is controlled by the value of editor.__view_attrs__:
|
|
||||||
// false / undefined - strip attrs
|
|
||||||
// true - call the handler XXX
|
|
||||||
__pre_parse__: function(text, editor, elem){
|
__pre_parse__: function(text, editor, elem){
|
||||||
// NOTE: we are intentionally neglecting system attrs here...
|
|
||||||
var [elem, attrs, system] = this.parseBlockAttrs(editor, text, elem)
|
var [elem, attrs, system] = this.parseBlockAttrs(editor, text, elem)
|
||||||
if(editor.__view_attrs__
|
// XXX use filter handler here...
|
||||||
&& attrs.length > 0){
|
return !editor.__view_attrs__ ?
|
||||||
attrs = editor.threadPlugins('__parse_attrs__', attrs, editor, elem)
|
elem.text
|
||||||
if(attrs && attrs.length > 0){
|
: elem.text +'\n'+ attrs
|
||||||
return text +'\n'+ attrs } }
|
},
|
||||||
return elem.text },
|
|
||||||
|
|
||||||
// XXX
|
// XXX
|
||||||
//__parse_attrs__: function(attrs, editor, elem){
|
__parse_attrs__: function(){
|
||||||
// return attrs }
|
// XXX
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -933,17 +903,12 @@ var JSONOutline = {
|
|||||||
|
|
||||||
__code_attrs__: false,
|
__code_attrs__: false,
|
||||||
__view_attrs__: false,
|
__view_attrs__: false,
|
||||||
__system_attrs__: [
|
|
||||||
'text',
|
|
||||||
'children',
|
|
||||||
],
|
|
||||||
__block_attrs__: {
|
__block_attrs__: {
|
||||||
id: 'attr',
|
id: 'attr',
|
||||||
collapsed: 'attr',
|
collapsed: 'attr',
|
||||||
focused: 'cls',
|
focused: 'cls',
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
||||||
// Plugins...
|
// Plugins...
|
||||||
//
|
//
|
||||||
// The order of plugins can be significant in the following cases:
|
// The order of plugins can be significant in the following cases:
|
||||||
@ -1210,7 +1175,6 @@ var JSONOutline = {
|
|||||||
// XXX add plugin hooks...
|
// XXX add plugin hooks...
|
||||||
// XXX add option to customize indent size...
|
// XXX add option to customize indent size...
|
||||||
text: function(node, indent, level){
|
text: function(node, indent, level){
|
||||||
var that = this
|
|
||||||
// .text(<indent>, <level>)
|
// .text(<indent>, <level>)
|
||||||
if(typeof(node) == 'string'){
|
if(typeof(node) == 'string'){
|
||||||
;[node, indent=' ', level=''] = [undefined, ...arguments] }
|
;[node, indent=' ', level=''] = [undefined, ...arguments] }
|
||||||
@ -1226,7 +1190,8 @@ var JSONOutline = {
|
|||||||
// attrs...
|
// attrs...
|
||||||
+ (Object.keys(elem)
|
+ (Object.keys(elem)
|
||||||
.reduce(function(res, attr){
|
.reduce(function(res, attr){
|
||||||
return that.__system_attrs__.includes(attr) ?
|
return (attr == 'text'
|
||||||
|
|| attr == 'children') ?
|
||||||
res
|
res
|
||||||
: res
|
: res
|
||||||
+ (elem[attr] ?
|
+ (elem[attr] ?
|
||||||
@ -1252,7 +1217,7 @@ var JSONOutline = {
|
|||||||
var attrs = []
|
var attrs = []
|
||||||
|
|
||||||
for(var [attr, value] of Object.entries({...data, ...parsed})){
|
for(var [attr, value] of Object.entries({...data, ...parsed})){
|
||||||
if(this.__system_attrs__.includes(attr)){
|
if(attr == 'children' || attr == 'text'){
|
||||||
continue }
|
continue }
|
||||||
var i
|
var i
|
||||||
var type = this.__block_attrs__[attr]
|
var type = this.__block_attrs__[attr]
|
||||||
@ -1675,13 +1640,9 @@ var Outline = {
|
|||||||
//this._syncTextSize(code, html) }
|
//this._syncTextSize(code, html) }
|
||||||
|
|
||||||
for(var [attr, value] of Object.entries({...data, ...parsed})){
|
for(var [attr, value] of Object.entries({...data, ...parsed})){
|
||||||
if(this.__system_attrs__.includes(attr)){
|
if(attr == 'children' || attr == 'text'){
|
||||||
continue }
|
continue }
|
||||||
|
|
||||||
// quoted value...
|
|
||||||
if(value && /^\s*([`'"])([^\1]*)\1\s*$/.test(value)){
|
|
||||||
value = value.replace(/^\s*([`'"])([^\1]*)\1\s*$/, '$2') }
|
|
||||||
|
|
||||||
var type = this.__block_attrs__[attr]
|
var type = this.__block_attrs__[attr]
|
||||||
if(type == 'cls'){
|
if(type == 'cls'){
|
||||||
value ?
|
value ?
|
||||||
@ -1697,7 +1658,6 @@ var Outline = {
|
|||||||
: node.removeAttribute(attr)
|
: node.removeAttribute(attr)
|
||||||
// dataset...
|
// dataset...
|
||||||
} else {
|
} else {
|
||||||
// remove attr...
|
|
||||||
if(value == null
|
if(value == null
|
||||||
|| value == 'null'
|
|| value == 'null'
|
||||||
|| value == 'undefined'){
|
|| value == 'undefined'){
|
||||||
|
|||||||
@ -143,14 +143,27 @@ var setup = function(){
|
|||||||
-
|
-
|
||||||
- ## ToDo:
|
- ## ToDo:
|
||||||
- ASAP: expand sub-tree on follow link...
|
- ASAP: expand sub-tree on follow link...
|
||||||
- ASAP TEST: attributes: finalize base mechanics...
|
- ASAP: attributes: finalize base mechanics:
|
||||||
|
- code filtering
|
||||||
|
```
|
||||||
|
.__code_attrs__(attrs, code, elem)
|
||||||
|
-> true
|
||||||
|
-> false
|
||||||
|
```
|
||||||
|
_system attrs are always hidden, the client can control whether the code is shown or not_
|
||||||
|
- view filtering
|
||||||
|
```
|
||||||
|
.__view_attrs__(attrs, code, elem)
|
||||||
|
-> str
|
||||||
|
-> undefined
|
||||||
|
```
|
||||||
|
- might be a good idea to change `.parseBlockAttrs(..)` to return an array of text and attrs (str) and handle the above `.__code_attrs__(..)` and `.__view_attrs__(..)` in the respective handlers...
|
||||||
- attributes: need to show/hide the attributes -- option?
|
- attributes: need to show/hide the attributes -- option?
|
||||||
attr::value
|
attr::value
|
||||||
- DONE `.__parse_code__(..)`: add data attributes to code if missing...
|
- `.__parse_code__(..)`: add data attributes to code if missing...
|
||||||
- DONE do we need `.__code_attrs__` / `.__view_attrs__`??? -- YES
|
- do we need `.__code_attrs__` / `.__view_attrs__`???
|
||||||
- DONE delete attr from code -- by setting it to `"null"` or `"undefined"`...
|
- handle attr delete correctly -- i.e. if shown attr removed from code -> delete attr...
|
||||||
- delete attr from code -- by removing it from attr list (when shown)...
|
- BUG? can't set `''` as attr value -- parser??
|
||||||
- DONE BUG? can't set `''` as attr value -- parser??
|
|
||||||
- TOC: tweaking: add args like depth, ... -- as attributes...
|
- TOC: tweaking: add args like depth, ... -- as attributes...
|
||||||
- TOC: should it be persistently generated as code and be serializable?
|
- TOC: should it be persistently generated as code and be serializable?
|
||||||
- simple use strategies:
|
- simple use strategies:
|
||||||
@ -276,7 +289,6 @@ var setup = function(){
|
|||||||
- `<editable/>` -- field marker
|
- `<editable/>` -- field marker
|
||||||
- each child node will copy the template and allow editing of only fields
|
- each child node will copy the template and allow editing of only fields
|
||||||
- not clear how to handle template changes...
|
- not clear how to handle template changes...
|
||||||
- DONE attributes: might be a good idea to prevent setting `.text` and `.children` attrs...
|
|
||||||
- DONE TOC: Q: should we have both manual and auto headings???
|
- DONE TOC: Q: should we have both manual and auto headings???
|
||||||
collapsed:: true
|
collapsed:: true
|
||||||
- IMHO: no...
|
- IMHO: no...
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user