jails-js 5.0.0-beta.13 → 5.0.0-beta.16

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/src/component.ts CHANGED
@@ -2,16 +2,14 @@ import morphdom from 'morphdom'
2
2
 
3
3
  import { rAF, dup, buildtemplates } from './utils'
4
4
  import { on, off, trigger } from './utils/events'
5
- import { publish, subscribe, unsubscribe } from './utils/pubsub'
5
+ import { publish, subscribe } from './utils/pubsub'
6
6
 
7
- type MainArgs = () => Array<Function>
8
-
9
- export default function Component( elm:HTMLElement, { module, dependencies, templates, components }) {
7
+ export default function Component( elm, { module, dependencies, templates, components }) {
10
8
 
11
9
  const options = getOptions( module )
12
10
  buildtemplates( elm, components, templates )
13
11
 
14
- const tplid:string|null = elm.getAttribute('tplid')
12
+ const tplid = elm.getAttribute('tplid')
15
13
  const template = tplid ? templates[tplid] : null
16
14
  const state = { data: module.model ? dup(module.model) : {} }
17
15
 
@@ -21,9 +19,8 @@ export default function Component( elm:HTMLElement, { module, dependencies, temp
21
19
  dependencies,
22
20
  publish,
23
21
  subscribe,
24
- unsubscribe,
25
22
 
26
- main(fn: MainArgs) {
23
+ main(fn) {
27
24
  options.main = fn
28
25
  },
29
26
 
@@ -35,15 +32,15 @@ export default function Component( elm:HTMLElement, { module, dependencies, temp
35
32
  options.onupdate = fn
36
33
  },
37
34
 
38
- on(eventName: string, selectorOrCallback: object | Function, callback: Function) {
35
+ on(eventName, selectorOrCallback, callback) {
39
36
  on(elm, eventName, selectorOrCallback, callback)
40
37
  },
41
38
 
42
- off(eventName: string, callback: Function) {
39
+ off(eventName, callback) {
43
40
  off(elm, eventName, callback)
44
41
  },
45
42
 
46
- trigger(eventName: string, target: string, args: any) {
43
+ trigger(eventName, target, args) {
47
44
  if (target.constructor === String) {
48
45
  Array
49
46
  .from(elm.querySelectorAll(target))
@@ -52,12 +49,12 @@ export default function Component( elm:HTMLElement, { module, dependencies, temp
52
49
  else trigger(elm, eventName, { args: target })
53
50
  },
54
51
 
55
- emit: (...args: any) => {
52
+ emit: ( ...args ) => {
56
53
  trigger(elm, args.shift(), { args: args })
57
54
  },
58
55
 
59
56
  state: {
60
- set( data: any ) {
57
+ set( data ) {
61
58
  if (data.constructor === Function) {
62
59
  const newstate = dup(state.data)
63
60
  data(newstate)
@@ -67,12 +64,12 @@ export default function Component( elm:HTMLElement, { module, dependencies, temp
67
64
  }
68
65
  return new Promise((resolve) => rAF(_ => rAF(resolve)))
69
66
  },
70
- get(): object {
67
+ get() {
71
68
  return dup(state.data)
72
69
  }
73
70
  },
74
71
 
75
- render(data: object = state.data) {
72
+ render(data = state.data) {
76
73
 
77
74
  if (!document.body.contains(elm))
78
75
  return
@@ -98,34 +95,34 @@ export default function Component( elm:HTMLElement, { module, dependencies, temp
98
95
  return { base, options }
99
96
  }
100
97
 
101
- const getOptions = (module: any) : any => ({
102
- main: (a:any) => a,
103
- unmount: (a:any) => a,
104
- onupdate: (a:any) => a,
105
- view: module.view ? module.view : (a:any) => a
98
+ const getOptions = (module) => ({
99
+ main: (a) => a,
100
+ unmount: (a) => a,
101
+ onupdate: (a) => a,
102
+ view: module.view ? module.view : (a) => a
106
103
  })
107
104
 
108
- const morphdomOptions = (_parent: HTMLElement, options: any) => ({
105
+ const morphdomOptions = (_parent, options ) => ({
109
106
 
110
107
  onNodeAdded: onUpdates(_parent, options),
111
108
  onElUpdated: onUpdates(_parent, options),
112
109
  onBeforeElChildrenUpdated: checkStatic,
113
110
  onBeforeElUpdated: checkStatic,
114
111
 
115
- getNodeKey(node: HTMLElement) {
112
+ getNodeKey(node) {
116
113
  if (node.nodeType === 1 && node.getAttribute('tplid'))
117
114
  return node.dataset.key || node.getAttribute('tplid')
118
115
  return false
119
116
  }
120
117
  })
121
118
 
122
- const checkStatic = (node: HTMLElement) => {
123
- if ('static' in node.dataset) {
119
+ const checkStatic = (node) => {
120
+ if ('static' in node.dataset || 'html-static' in node.attributes) {
124
121
  return false
125
122
  }
126
123
  }
127
124
 
128
- const onUpdates = (_parent: HTMLElement, options: any) => (node: HTMLElement) => {
125
+ const onUpdates = (_parent, options) => (node) => {
129
126
 
130
127
  if (node.nodeType === 1) {
131
128
 
@@ -134,7 +131,7 @@ const onUpdates = (_parent: HTMLElement, options: any) => (node: HTMLElement) =>
134
131
  const scope = JSON.parse((node.getAttribute('scope') ||'').replace(/\'/g, '\"'))
135
132
 
136
133
  Array.from(node.querySelectorAll('[tplid]'))
137
- .map((el: any) => {
134
+ .map((el) => {
138
135
  const data = Object.assign({}, _parent.base.state.get(), scope)
139
136
  options.onupdate(data)
140
137
  el.base.render(data)
package/src/index.ts CHANGED
@@ -1,12 +1,13 @@
1
+
1
2
  import { buildtemplates } from './utils'
2
3
  import Element from './element'
3
4
 
4
- export const templates = {} as any
5
- export const components = {} as any
5
+ const templates = {}
6
+ const components = {}
6
7
 
7
8
  export default {
8
9
 
9
- register( name: string, module: any, dependencies: object = {} ) {
10
+ register( name:string, module:any, dependencies: object ) {
10
11
  components[name] = { name, module, dependencies }
11
12
  },
12
13
 
@@ -21,7 +22,7 @@ const registerComponents = () => {
21
22
  Object
22
23
  .values( components )
23
24
  .forEach( (component) => {
24
- const { name, module, dependencies } = component as any
25
+ const { name, module, dependencies } = component
25
26
  const Base = Element(module, dependencies, templates, components)
26
27
  customElements.define(name, Base)
27
28
  })
@@ -1,14 +1,10 @@
1
1
  import { compile, defaultConfig, filters } from 'squirrelly'
2
- import { SqrlConfig } from 'squirrelly/dist/types/config'
3
2
  import { decodeHtmlEntities } from './utils'
4
3
 
5
- const defaultOptions: SqrlConfig = {
6
- ...defaultConfig,
7
- tags: ['{', '}'],
8
- useWith: true
9
- }
4
+ defaultConfig.tags = ['{', '}']
5
+ defaultConfig.useWith = true
10
6
 
11
- export default function templateSystem( element: HTMLElement ) {
7
+ export default function templateSystem( element ) {
12
8
 
13
9
  const tree = document.createElement('template')
14
10
 
@@ -22,24 +18,24 @@ export default function templateSystem( element: HTMLElement ) {
22
18
  .replace(/html-/g, '')
23
19
  )
24
20
 
25
- const template = compile(html, defaultOptions)
21
+ const template = compile(html, defaultConfig)
26
22
 
27
- return ( data: object ) => {
28
- return template(data, defaultOptions)
23
+ return ( data ) => {
24
+ return template(data, defaultConfig)
29
25
  }
30
26
  }
31
27
 
32
28
  /**@Directives */
33
29
 
34
- const directives = (vdom: DocumentFragment) => {
30
+ const directives = (vdom) => {
35
31
 
36
32
  const nodes = Array
37
33
  .from(vdom.querySelectorAll('[html-for],[html-if],[html-foreach]'))
38
- .reverse() as Array<HTMLElement>
34
+ .reverse()
39
35
 
40
36
  if (nodes.length) {
41
37
 
42
- nodes.forEach((node: HTMLElement ) => {
38
+ nodes.forEach(( node ) => {
43
39
  if (node.getAttribute('html-foreach')) {
44
40
  const instruction = node.getAttribute('html-foreach') || ''
45
41
  const split = instruction.match(/(.*)\sin\s(.*)/) || ''
@@ -84,7 +80,7 @@ filters.define('JSON', (scope, index, varname) => {
84
80
  return JSON.stringify(newobject)
85
81
  })
86
82
 
87
- const wrap = (open: Text, node :HTMLElement, close: Text) => {
83
+ const wrap = (open, node, close) => {
88
84
  node.parentNode?.insertBefore(open, node)
89
85
  node.parentNode?.insertBefore(close, node.nextSibling)
90
86
  }
@@ -16,10 +16,10 @@ export const uuid = () => {
16
16
  })
17
17
  }
18
18
 
19
- export const stripTemplateTag = ( element:HTMLElement | DocumentFragment | HTMLTemplateElement ) => {
19
+ export const stripTemplateTag = ( element ) => {
20
20
  const templates = Array.from(element.querySelectorAll('template'))
21
21
  // https://gist.github.com/harmenjanssen/07e425248779c65bc5d11b02fb913274
22
- templates.forEach((template: HTMLTemplateElement) => {
22
+ templates.forEach((template) => {
23
23
  template.parentNode?.replaceChild(template.content, template)
24
24
  stripTemplateTag(template.content)
25
25
  })
@@ -29,7 +29,7 @@ export const dup = (o) => {
29
29
  return JSON.parse(JSON.stringify(o))
30
30
  }
31
31
 
32
- export const createTemplateId = (element: HTMLElement, templates: any ) => {
32
+ export const createTemplateId = (element, templates ) => {
33
33
 
34
34
  const tplid = element.getAttribute('tplid')
35
35
 
@@ -40,21 +40,21 @@ export const createTemplateId = (element: HTMLElement, templates: any ) => {
40
40
  }
41
41
  }
42
42
 
43
- export const buildtemplates = ( target: any, components: any, templates: any ) => {
43
+ export const buildtemplates = ( target, components, templates ) => {
44
44
 
45
45
  return Array
46
46
  .from(target.querySelectorAll('*'))
47
- .filter((node: any) => node.tagName.toLowerCase() in components)
47
+ .filter((node) => node.tagName.toLowerCase() in components)
48
48
  .reverse()
49
- .map((node: any) => {
49
+ .map((node) => {
50
50
  Array.from(node.querySelectorAll('template'))
51
- .map(template => buildtemplates(template.content, components, templates))
51
+ .map((template) => buildtemplates(template.content, components, templates))
52
52
  createTemplateId(node, templates)
53
53
  return node
54
54
  })
55
55
  }
56
56
 
57
- export const decodeHtmlEntities = ( str:string ) => {
57
+ export const decodeHtmlEntities = ( str ) => {
58
58
  textarea.innerHTML = str
59
59
  return textarea.value
60
60
  }
@@ -1,25 +1,20 @@
1
1
  const topics: any = {}
2
2
  const _async: any = {}
3
3
 
4
- export const publish = (name: string, params: any) => {
4
+ export const publish = (name, params) => {
5
5
  _async[name] = Object.assign({}, _async[name], params)
6
6
  if (topics[name])
7
7
  topics[name].forEach(topic => topic(params))
8
8
  }
9
9
 
10
- export const subscribe = (name: string, method: Function) => {
10
+ export const subscribe = (name, method) => {
11
11
  topics[name] = topics[name] || []
12
12
  topics[name].push(method)
13
13
  if (name in _async) {
14
14
  method(_async[name])
15
15
  }
16
- }
17
-
18
- export const unsubscribe = ( topic: any ) => {
19
- topics[topic.name] = (topics[topic.name] || [])
20
- .filter((t: any) => t != topic.method)
21
- if (!topics[topic.name].length) {
22
- delete topics[topic.name]
23
- delete _async[topic.name]
16
+ return () => {
17
+ topics[name] = topics[name].filter( fn => fn != method )
24
18
  }
25
19
  }
20
+
package/tsconfig.json CHANGED
@@ -1,13 +1,106 @@
1
1
  {
2
- "compilerOptions": {
3
- "target": "ESNext",
4
- "esModuleInterop":true,
5
- "allowJs": true,
6
- "declaration": true,
7
- "emitDeclarationOnly": true,
8
- "declarationDir": "./dist/types"
9
- },
10
- "include": [
11
- "src/**/*"
12
- ]
13
- }
2
+ "compilerOptions": {
3
+ /* Visit https://aka.ms/tsconfig to read more about this file */
4
+
5
+ /* Projects */
6
+ // "incremental": true, /* Save .tsbuildinfo files to allow for incremental compilation of projects. */
7
+ // "composite": true, /* Enable constraints that allow a TypeScript project to be used with project references. */
8
+ // "tsBuildInfoFile": "./.tsbuildinfo", /* Specify the path to .tsbuildinfo incremental compilation file. */
9
+ // "disableSourceOfProjectReferenceRedirect": true, /* Disable preferring source files instead of declaration files when referencing composite projects. */
10
+ // "disableSolutionSearching": true, /* Opt a project out of multi-project reference checking when editing. */
11
+ // "disableReferencedProjectLoad": true, /* Reduce the number of projects loaded automatically by TypeScript. */
12
+
13
+ /* Language and Environment */
14
+ "target": "ES2015", /* Set the JavaScript language version for emitted JavaScript and include compatible library declarations. */
15
+ "lib": ["es2015", "dom"], /* Specify a set of bundled library declaration files that describe the target runtime environment. */
16
+ // "jsx": "preserve", /* Specify what JSX code is generated. */
17
+ // "experimentalDecorators": true, /* Enable experimental support for TC39 stage 2 draft decorators. */
18
+ // "emitDecoratorMetadata": true, /* Emit design-type metadata for decorated declarations in source files. */
19
+ // "jsxFactory": "", /* Specify the JSX factory function used when targeting React JSX emit, e.g. 'React.createElement' or 'h'. */
20
+ // "jsxFragmentFactory": "", /* Specify the JSX Fragment reference used for fragments when targeting React JSX emit e.g. 'React.Fragment' or 'Fragment'. */
21
+ // "jsxImportSource": "", /* Specify module specifier used to import the JSX factory functions when using 'jsx: react-jsx*'. */
22
+ // "reactNamespace": "", /* Specify the object invoked for 'createElement'. This only applies when targeting 'react' JSX emit. */
23
+ // "noLib": true, /* Disable including any library files, including the default lib.d.ts. */
24
+ // "useDefineForClassFields": true, /* Emit ECMAScript-standard-compliant class fields. */
25
+ // "moduleDetection": "auto", /* Control what method is used to detect module-format JS files. */
26
+
27
+ /* Modules */
28
+ "module":"CommonJS", /* Specify what module code is generated. */
29
+ // "rootDir": "./src", /* Specify the root folder within your source files. */
30
+ "moduleResolution": "node", /* Specify how TypeScript looks up a file from a given module specifier. */
31
+ // "baseUrl": "./", /* Specify the base directory to resolve non-relative module names. */
32
+ // "paths": {}, /* Specify a set of entries that re-map imports to additional lookup locations. */
33
+ // "rootDirs": [], /* Allow multiple folders to be treated as one when resolving modules. */
34
+ // "typeRoots": [], /* Specify multiple folders that act like './node_modules/@types'. */
35
+ // "types": [], /* Specify type package names to be included without being referenced in a source file. */
36
+ // "allowUmdGlobalAccess": true, /* Allow accessing UMD globals from modules. */
37
+ // "moduleSuffixes": [], /* List of file name suffixes to search when resolving a module. */
38
+ // "resolveJsonModule": true, /* Enable importing .json files. */
39
+ // "noResolve": true, /* Disallow 'import's, 'require's or '<reference>'s from expanding the number of files TypeScript should add to a project. */
40
+
41
+ /* JavaScript Support */
42
+ // "allowJs": true, /* Allow JavaScript files to be a part of your program. Use the 'checkJS' option to get errors from these files. */
43
+ // "checkJs": true, /* Enable error reporting in type-checked JavaScript files. */
44
+ // "maxNodeModuleJsDepth": 1, /* Specify the maximum folder depth used for checking JavaScript files from 'node_modules'. Only applicable with 'allowJs'. */
45
+
46
+ /* Emit */
47
+ "declaration": true, /* Generate .d.ts files from TypeScript and JavaScript files in your project. */
48
+ // "declarationMap": true, /* Create sourcemaps for d.ts files. */
49
+ "emitDeclarationOnly": true, /* Only output d.ts files and not JavaScript files. */
50
+ // "sourceMap": true, /* Create source map files for emitted JavaScript files. */
51
+ // "outFile": "types/index.d.ts", /* Specify a file that bundles all outputs into one JavaScript file. If 'declaration' is true, also designates a file that bundles all .d.ts output. */
52
+ "outDir": "types", /* Specify an output folder for all emitted files. */
53
+ // "removeComments": true, /* Disable emitting comments. */
54
+ // "noEmit": true, /* Disable emitting files from a compilation. */
55
+ // "importHelpers": true, /* Allow importing helper functions from tslib once per project, instead of including them per-file. */
56
+ // "importsNotUsedAsValues": "remove", /* Specify emit/checking behavior for imports that are only used for types. */
57
+ // "downlevelIteration": true, /* Emit more compliant, but verbose and less performant JavaScript for iteration. */
58
+ // "sourceRoot": "", /* Specify the root path for debuggers to find the reference source code. */
59
+ // "mapRoot": "", /* Specify the location where debugger should locate map files instead of generated locations. */
60
+ // "inlineSourceMap": true, /* Include sourcemap files inside the emitted JavaScript. */
61
+ // "inlineSources": true, /* Include source code in the sourcemaps inside the emitted JavaScript. */
62
+ // "emitBOM": true, /* Emit a UTF-8 Byte Order Mark (BOM) in the beginning of output files. */
63
+ // "newLine": "crlf", /* Set the newline character for emitting files. */
64
+ // "stripInternal": true, /* Disable emitting declarations that have '@internal' in their JSDoc comments. */
65
+ // "noEmitHelpers": true, /* Disable generating custom helper functions like '__extends' in compiled output. */
66
+ // "noEmitOnError": true, /* Disable emitting files if any type checking errors are reported. */
67
+ // "preserveConstEnums": true, /* Disable erasing 'const enum' declarations in generated code. */
68
+ // "declarationDir": "./dist/types", /* Specify the output directory for generated declaration files. */
69
+ // "preserveValueImports": true, /* Preserve unused imported values in the JavaScript output that would otherwise be removed. */
70
+
71
+ /* Interop Constraints */
72
+ // "isolatedModules": true, /* Ensure that each file can be safely transpiled without relying on other imports. */
73
+ // "allowSyntheticDefaultImports": true, /* Allow 'import x from y' when a module doesn't have a default export. */
74
+ "esModuleInterop": true, /* Emit additional JavaScript to ease support for importing CommonJS modules. This enables 'allowSyntheticDefaultImports' for type compatibility. */
75
+ // "preserveSymlinks": true, /* Disable resolving symlinks to their realpath. This correlates to the same flag in node. */
76
+ "forceConsistentCasingInFileNames": true, /* Ensure that casing is correct in imports. */
77
+
78
+ /* Type Checking */
79
+ // "strict": true, /* Enable all strict type-checking options. */
80
+ "noImplicitAny": false, /* Enable error reporting for expressions and declarations with an implied 'any' type. */
81
+ // "strictNullChecks": true, /* When type checking, take into account 'null' and 'undefined'. */
82
+ // "strictFunctionTypes": true, /* When assigning functions, check to ensure parameters and the return values are subtype-compatible. */
83
+ // "strictBindCallApply": true, /* Check that the arguments for 'bind', 'call', and 'apply' methods match the original function. */
84
+ // "strictPropertyInitialization": true, /* Check for class properties that are declared but not set in the constructor. */
85
+ // "noImplicitThis": true, /* Enable error reporting when 'this' is given the type 'any'. */
86
+ // "useUnknownInCatchVariables": true, /* Default catch clause variables as 'unknown' instead of 'any'. */
87
+ // "alwaysStrict": true, /* Ensure 'use strict' is always emitted. */
88
+ // "noUnusedLocals": true, /* Enable error reporting when local variables aren't read. */
89
+ // "noUnusedParameters": true, /* Raise an error when a function parameter isn't read. */
90
+ // "exactOptionalPropertyTypes": true, /* Interpret optional property types as written, rather than adding 'undefined'. */
91
+ // "noImplicitReturns": true, /* Enable error reporting for codepaths that do not explicitly return in a function. */
92
+ // "noFallthroughCasesInSwitch": true, /* Enable error reporting for fallthrough cases in switch statements. */
93
+ // "noUncheckedIndexedAccess": true, /* Add 'undefined' to a type when accessed using an index. */
94
+ // "noImplicitOverride": true, /* Ensure overriding members in derived classes are marked with an override modifier. */
95
+ // "noPropertyAccessFromIndexSignature": true, /* Enforces using indexed accessors for keys declared using an indexed type. */
96
+ // "allowUnusedLabels": true, /* Disable error reporting for unused labels. */
97
+ // "allowUnreachableCode": true, /* Disable error reporting for unreachable code. */
98
+
99
+ /* Completeness */
100
+ // "skipDefaultLibCheck": true, /* Skip type checking .d.ts files that are included with TypeScript. */
101
+ "skipLibCheck": true /* Skip type checking all .d.ts files. */
102
+ },
103
+ "files": [
104
+ "src/index.ts"
105
+ ]
106
+ }
@@ -0,0 +1,32 @@
1
+ export default function Component(elm: any, { module, dependencies, templates, components }: {
2
+ module: any;
3
+ dependencies: any;
4
+ templates: any;
5
+ components: any;
6
+ }): {
7
+ base: {
8
+ template: any;
9
+ elm: any;
10
+ dependencies: any;
11
+ publish: (name: any, params: any) => void;
12
+ subscribe: (name: any, method: any) => () => void;
13
+ main(fn: any): void;
14
+ unmount(fn: any): void;
15
+ onupdate(fn: any): void;
16
+ on(eventName: any, selectorOrCallback: any, callback: any): void;
17
+ off(eventName: any, callback: any): void;
18
+ trigger(eventName: any, target: any, args: any): void;
19
+ emit: (...args: any[]) => void;
20
+ state: {
21
+ set(data: any): Promise<unknown>;
22
+ get(): any;
23
+ };
24
+ render(data?: any): void;
25
+ };
26
+ options: {
27
+ main: (a: any) => any;
28
+ unmount: (a: any) => any;
29
+ onupdate: (a: any) => any;
30
+ view: any;
31
+ };
32
+ };