kdu-client-only 2.0.0

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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2022-present NKDuy
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,93 @@
1
+ # kdu-client-only
2
+
3
+ ## Install
4
+
5
+ ```bash
6
+ yarn add kdu-client-only
7
+ ```
8
+
9
+ ## Usage
10
+
11
+ ```kdu
12
+ <template>
13
+ <div id="app">
14
+ <h1>My Website</h1>
15
+ <client-only>
16
+ <!-- this component will only be rendered on client-side -->
17
+ <comments />
18
+ </client-only>
19
+ </div>
20
+ </template>
21
+
22
+ <script>
23
+ import ClientOnly from 'kdu-client-only'
24
+
25
+ export default {
26
+ components: {
27
+ ClientOnly
28
+ }
29
+ }
30
+ </script>
31
+ ```
32
+
33
+ ### Placeholder
34
+
35
+ Use a slot or text as placeholder until `<client-only />` is mounted on client-side.
36
+
37
+ eg, show a loading indicator.
38
+
39
+ ```kdu
40
+ <template>
41
+ <div id="app">
42
+ <h1>My Website</h1>
43
+ <!-- use slot -->
44
+ <client-only>
45
+ <comments />
46
+      <comments-placeholder slot="placeholder" />
47
+    </client-only>
48
+ <!-- or use text -->
49
+ <client-only placeholder="Loading...">
50
+ <comments />
51
+ </client-only>
52
+ </div>
53
+ </template>
54
+
55
+ <script>
56
+ import ClientOnly from 'kdu-client-only'
57
+
58
+ export default {
59
+ components: {
60
+ ClientOnly
61
+ }
62
+ }
63
+ </script>
64
+ ```
65
+
66
+ By default the placeholder will be wrapped in a `div` tag, however you can use `placeholderTag` prop to customize it:
67
+
68
+ ```kdu
69
+ <client-only placeholder="loading" placeholder-tag="span">
70
+ <comments />
71
+ </client-only>
72
+ ```
73
+
74
+ And you get:
75
+
76
+ ```html
77
+ <span class="client-only-placeholder">
78
+ loading
79
+ </span>
80
+ ```
81
+
82
+ If prop `placeholder` is an empty string (or `null`) and no `placeholder`
83
+ slot is found, then `<client-only>` will render the Kdu placeholder element `<!---->`
84
+ instead of rendering the `placholder-tag` during SSR render.
85
+
86
+ ## Development
87
+
88
+ ```bash
89
+ yarn install
90
+
91
+ # Run example
92
+ yarn example
93
+ ```
@@ -0,0 +1,51 @@
1
+ /*!
2
+ * kdu-client-only v2.0.0
3
+ * (c) 2022-present NKDuy
4
+ * Released under the MIT License.
5
+ */
6
+ 'use strict';
7
+
8
+ var index = {
9
+ name: 'ClientOnly',
10
+ functional: true,
11
+ props: {
12
+ placeholder: String,
13
+ placeholderTag: {
14
+ type: String,
15
+ default: 'div'
16
+ }
17
+ },
18
+ render: function render(h, ref) {
19
+ var parent = ref.parent;
20
+ var slots = ref.slots;
21
+ var props = ref.props;
22
+
23
+ var ref$1 = slots();
24
+ var defaultSlot = ref$1.default; if ( defaultSlot === void 0 ) defaultSlot = [];
25
+ var placeholderSlot = ref$1.placeholder;
26
+
27
+ if (parent._isMounted) {
28
+ return defaultSlot
29
+ }
30
+
31
+ parent.$once('hook:mounted', function () {
32
+ parent.$forceUpdate();
33
+ });
34
+
35
+ if (props.placeholderTag && (props.placeholder || placeholderSlot)) {
36
+ return h(
37
+ props.placeholderTag,
38
+ {
39
+ class: ['client-only-placeholder']
40
+ },
41
+ props.placeholder || placeholderSlot
42
+ )
43
+ }
44
+
45
+ // Return a placeholder element for each child in the default slot
46
+ // Or if no children return a single placeholder
47
+ return defaultSlot.length > 0 ? defaultSlot.map(function () { return h(false); }) : h(false)
48
+ }
49
+ };
50
+
51
+ module.exports = index;
@@ -0,0 +1,57 @@
1
+ /*!
2
+ * kdu-client-only v2.0.0
3
+ * (c) 2022-present NKDuy
4
+ * Released under the MIT License.
5
+ */
6
+ (function (global, factory) {
7
+ typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() :
8
+ typeof define === 'function' && define.amd ? define(factory) :
9
+ (global.ClientOnly = factory());
10
+ }(this, (function () { 'use strict';
11
+
12
+ var index = {
13
+ name: 'ClientOnly',
14
+ functional: true,
15
+ props: {
16
+ placeholder: String,
17
+ placeholderTag: {
18
+ type: String,
19
+ default: 'div'
20
+ }
21
+ },
22
+ render: function render(h, ref) {
23
+ var parent = ref.parent;
24
+ var slots = ref.slots;
25
+ var props = ref.props;
26
+
27
+ var ref$1 = slots();
28
+ var defaultSlot = ref$1.default; if ( defaultSlot === void 0 ) defaultSlot = [];
29
+ var placeholderSlot = ref$1.placeholder;
30
+
31
+ if (parent._isMounted) {
32
+ return defaultSlot
33
+ }
34
+
35
+ parent.$once('hook:mounted', function () {
36
+ parent.$forceUpdate();
37
+ });
38
+
39
+ if (props.placeholderTag && (props.placeholder || placeholderSlot)) {
40
+ return h(
41
+ props.placeholderTag,
42
+ {
43
+ class: ['client-only-placeholder']
44
+ },
45
+ props.placeholder || placeholderSlot
46
+ )
47
+ }
48
+
49
+ // Return a placeholder element for each child in the default slot
50
+ // Or if no children return a single placeholder
51
+ return defaultSlot.length > 0 ? defaultSlot.map(function () { return h(false); }) : h(false)
52
+ }
53
+ };
54
+
55
+ return index;
56
+
57
+ })));
@@ -0,0 +1,7 @@
1
+ /*!
2
+ * kdu-client-only v2.0.0
3
+ * (c) 2022-present NKDuy
4
+ * Released under the MIT License.
5
+ */
6
+ !function(e,n){"object"==typeof exports&&"undefined"!=typeof module?module.exports=n():"function"==typeof define&&define.amd?define(n):e.ClientOnly=n()}(this,function(){"use strict";return{name:"ClientOnly",functional:!0,props:{placeholder:String,placeholderTag:{type:String,default:"div"}},render:function(e,n){var o=n.parent,t=n.slots,l=n.props,r=t(),d=r.default;void 0===d&&(d=[]);var a=r.placeholder;return o._isMounted?d:(o.$once("hook:mounted",function(){o.$forceUpdate()}),l.placeholderTag&&(l.placeholder||a)?e(l.placeholderTag,{class:["client-only-placeholder"]},l.placeholder||a):d.length>0?d.map(function(){return e(!1)}):e(!1))}}});
7
+ //# sourceMappingURL=kdu-client-only.min.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":null,"sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;"}
package/package.json ADDED
@@ -0,0 +1,41 @@
1
+ {
2
+ "name": "kdu-client-only",
3
+ "version": "2.0.0",
4
+ "description": "kdu component to wrap non SSR friendly components",
5
+ "repository": {
6
+ "url": "khanhduy1407/kdu-client-only",
7
+ "type": "git"
8
+ },
9
+ "main": "dist/kdu-client-only.common.js",
10
+ "unpkg": "dist/kdu-client-only.min.js",
11
+ "files": [
12
+ "dist"
13
+ ],
14
+ "scripts": {
15
+ "lint": "xo",
16
+ "build": "npm run build:cjs && npm run build:umd",
17
+ "build:cjs": "bili --format cjs",
18
+ "build:umd": "bili --format umd --compress",
19
+ "prepublish": "npm run build",
20
+ "example": "poi"
21
+ },
22
+ "poi": {
23
+ "entry": "example/index.js",
24
+ "dist": "example/dist"
25
+ },
26
+ "author": "NKDuy",
27
+ "license": "MIT",
28
+ "dependencies": {},
29
+ "devDependencies": {
30
+ "bili": "^0.16.0-rc.1",
31
+ "eslint-config-rem": "^3.0.0",
32
+ "poi": "^9.3.1",
33
+ "xo": "^0.18.0"
34
+ },
35
+ "xo": {
36
+ "extends": "rem/prettier",
37
+ "ignores": [
38
+ "example/**"
39
+ ]
40
+ }
41
+ }