@bigbinary/neeto-templates-frontend 1.1.16 → 1.1.18
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/README.md +136 -10
- package/app/javascript/src/translations/en.json +1 -1
- package/dist/index.cjs.js +22 -23
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.js +16 -17
- package/dist/index.js.map +1 -1
- package/package.json +45 -41
package/README.md
CHANGED
|
@@ -1,18 +1,144 @@
|
|
|
1
1
|
# neeto-templates-nano
|
|
2
|
+
The `neeto-templates-nano` facilitates the administration of templates and template settings within neeto applications. The nano exports the `@bigbinary/neeto-templates-frontend` NPM package and `neeto-templates-engine` Rails engine for development.
|
|
2
3
|
|
|
3
|
-
|
|
4
|
+
# Contents
|
|
5
|
+
1. [Development with Host Application](#development-with-host-application)
|
|
6
|
+
- [Engine](#engine)
|
|
7
|
+
* [Installation](#installation)
|
|
8
|
+
* [Usage](#usage)
|
|
9
|
+
- [Frontend package](#frontend-package)
|
|
10
|
+
* [Installation](#installation-1)
|
|
11
|
+
* [Components](#components)
|
|
12
|
+
* [Other Functions](#other-functions)
|
|
4
13
|
|
|
5
|
-
|
|
14
|
+
2. [Instructions for Publishing](#instructions-for-publishing)
|
|
6
15
|
|
|
7
|
-
|
|
8
|
-
|
|
16
|
+
# Development with Host Application
|
|
17
|
+
## Engine
|
|
18
|
+
The engine is used to manage templates and template settings across neeto products.
|
|
9
19
|
|
|
10
|
-
|
|
20
|
+
### Installation
|
|
21
|
+
1. Add this line to your application's Gemfile:
|
|
22
|
+
```ruby
|
|
23
|
+
source "NEETO_GEM_SERVER_URL" do
|
|
24
|
+
# ..existing gems
|
|
11
25
|
|
|
12
|
-
|
|
13
|
-
|
|
26
|
+
gem 'neeto-templates-engine'
|
|
27
|
+
end
|
|
28
|
+
```
|
|
29
|
+
2. And then execute:
|
|
30
|
+
```shell
|
|
31
|
+
bundle install
|
|
32
|
+
```
|
|
33
|
+
3. Run the command to bring in all migrations, routes, models, associations, and controllers required from the engine to the host application:
|
|
34
|
+
```shell
|
|
35
|
+
bundle exec rails neeto_templates_engine:install
|
|
36
|
+
```
|
|
37
|
+
This will prompt the user to enter the resource model name. The resource model name is the name of the model that will be used as a template. For example, if the resource model name is `Form`, this will dynamically generate all necessary associations, routes, and controllers required for the `neeto_templates_engine` to work with the `Form` model.
|
|
14
38
|
|
|
15
|
-
|
|
39
|
+
> **_Note:_** _You might need to re-arrange the associations statements which
|
|
40
|
+
> are normally inserted to top most lines of the file, to satisfy the Rails
|
|
41
|
+
> standards._
|
|
16
42
|
|
|
17
|
-
|
|
18
|
-
|
|
43
|
+
4. Add the migrations to the database:
|
|
44
|
+
```shell
|
|
45
|
+
bundle exec rails db:migrate
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
### Usage
|
|
49
|
+
|
|
50
|
+
The `neeto_templates_engine` whitelists the `templates` subdomain for creation of the templates. All the entities (sites/forms) created in the `templates` subdomain are fetched as templates in the other subdomains.
|
|
51
|
+
|
|
52
|
+
You can learn more about the setup and usage here:
|
|
53
|
+
1. [Models](./docs/engine/models.md)
|
|
54
|
+
2. [Controllers](./docs/engine/controllers.md)
|
|
55
|
+
|
|
56
|
+
## Frontend package
|
|
57
|
+
|
|
58
|
+
To seamlessly integrate `NeetoTemplatesNano` into your host app, it iss essential to whitelist the `templates` subdomain. The entities built under this subdomain will be the listed as templates in the `CreateTemplateModal` component.
|
|
59
|
+
|
|
60
|
+
### Installation
|
|
61
|
+
Install the latest `NeetoTemplatesNano` package using the below command:
|
|
62
|
+
|
|
63
|
+
```shell
|
|
64
|
+
yarn add @bigbinary/neeto-templates-frontend
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
Install the dependency package:
|
|
68
|
+
|
|
69
|
+
```shell
|
|
70
|
+
yarn add @tailwindcss/line-clamp
|
|
71
|
+
```
|
|
72
|
+
Once installed add the plugin to your `tailwind.config.js` file:
|
|
73
|
+
|
|
74
|
+
```js
|
|
75
|
+
plugins: [require("@tailwindcss/line-clamp")]
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
### Components
|
|
79
|
+
#### `CreateTemplateModal` ([source code](https://github.com/bigbinary/neeto-templates-nano/blob/aec3368475c252284a25820c08ff151c1cdd254c/app/javascript/src/components/CreateTemplateModal/index.jsx))
|
|
80
|
+
The CreateTemplateModal component is a React component used for creating and previewing templates within a web application. It provides a user interface for users to create templates and view their details.
|
|
81
|
+
|
|
82
|
+
##### Props
|
|
83
|
+
- `isOpen`: A boolean indicating whether the modal is open or closed.
|
|
84
|
+
- `onClose`: A function to close the modal.
|
|
85
|
+
- `isCreating`: A boolean flag indicating whether a template is currently being created.
|
|
86
|
+
- `refetchResource`: A function to refetch template resources.
|
|
87
|
+
- `onCreate`: A function to handle template creation.
|
|
88
|
+
- `afterCreate`: A function to perform actions after template creation.
|
|
89
|
+
|
|
90
|
+
##### Usage
|
|
91
|
+
```jsx
|
|
92
|
+
import React from "react";
|
|
93
|
+
|
|
94
|
+
import { CreateTemplateModal } from "@bigbinary/neeto-templates-frontend";
|
|
95
|
+
|
|
96
|
+
const App = () => {
|
|
97
|
+
return (
|
|
98
|
+
<CreateTemplateModal
|
|
99
|
+
isOpen
|
|
100
|
+
onClose={() => {}}
|
|
101
|
+
isCreating={false}
|
|
102
|
+
refetchResource={() => {}}
|
|
103
|
+
onCreate={() => {}}
|
|
104
|
+
afterCreate={() => {}}
|
|
105
|
+
/>
|
|
106
|
+
);
|
|
107
|
+
};
|
|
108
|
+
```
|
|
109
|
+
|
|
110
|
+
#### `TemplateSettings` ([source code](https://github.com/bigbinary/neeto-templates-nano/blob/aec3368475c252284a25820c08ff151c1cdd254c/app/javascript/src/components/TemplateSettings/index.jsx))
|
|
111
|
+
The TemplateSettings component is a React component used for configuring and editing template settings within a web application. It provides a user interface for users to customize various aspects of a template, including its image, tags, and preview.
|
|
112
|
+
|
|
113
|
+
##### Props
|
|
114
|
+
- `onCancelTemplatePreview`: A function to handle canceling the template preview.
|
|
115
|
+
- `breadcrumbs`: An array of breadcrumb items for navigation.
|
|
116
|
+
- `className`: A CSS class name for styling.
|
|
117
|
+
|
|
118
|
+
##### Usage
|
|
119
|
+
```jsx
|
|
120
|
+
import React from "react";
|
|
121
|
+
|
|
122
|
+
import { TemplateSettings } from "@bigbinary/neeto-templates-frontend";
|
|
123
|
+
|
|
124
|
+
const App = () => {
|
|
125
|
+
const breadcrumbs = [
|
|
126
|
+
{
|
|
127
|
+
link: "/forms",
|
|
128
|
+
text: "Forms",
|
|
129
|
+
},
|
|
130
|
+
];
|
|
131
|
+
return (
|
|
132
|
+
<TemplateSettings
|
|
133
|
+
onCancelTemplatePreview={() => {}}
|
|
134
|
+
breadcrumbs={breadcrumbs}
|
|
135
|
+
/>
|
|
136
|
+
);
|
|
137
|
+
};
|
|
138
|
+
```
|
|
139
|
+
|
|
140
|
+
Use the `PrivateRoute` component to conditionally render this component only for the `templates` subdomain.
|
|
141
|
+
|
|
142
|
+
# Instructions for Publishing
|
|
143
|
+
|
|
144
|
+
Consult the [building and releasing packages](https://neeto-engineering.neetokb.com/articles/building-and-releasing-packages) guide for details on how to publish.
|
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
"neetoTemplate": {
|
|
9
9
|
"templates": {
|
|
10
10
|
"createNewEntity": "Create new {{taxonomies.entity.singular}}",
|
|
11
|
-
"description": "Select template
|
|
11
|
+
"description": "Select a template to get started with building your {{taxonomies.entity.singular}}.",
|
|
12
12
|
"blankCard": {
|
|
13
13
|
"title": "Start from scratch",
|
|
14
14
|
"description": "A blank slate"
|
package/dist/index.cjs.js
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
4
|
|
|
5
5
|
var React = require('react');
|
|
6
|
-
var
|
|
6
|
+
var neetocist = require('neetocist');
|
|
7
7
|
var neetoui = require('@bigbinary/neetoui');
|
|
8
8
|
var PageLoader = require('@bigbinary/neeto-molecules/PageLoader');
|
|
9
9
|
var Search = require('@bigbinary/neeto-molecules/Search');
|
|
@@ -1889,7 +1889,6 @@ var arrayPrefixGenerators = {
|
|
|
1889
1889
|
};
|
|
1890
1890
|
|
|
1891
1891
|
var isArray$1 = Array.isArray;
|
|
1892
|
-
var split = String.prototype.split;
|
|
1893
1892
|
var push = Array.prototype.push;
|
|
1894
1893
|
var pushToArray = function (arr, valueOrArray) {
|
|
1895
1894
|
push.apply(arr, isArray$1(valueOrArray) ? valueOrArray : [valueOrArray]);
|
|
@@ -1991,14 +1990,6 @@ var stringify$1 = function stringify(
|
|
|
1991
1990
|
if (isNonNullishPrimitive(obj) || utils$1.isBuffer(obj)) {
|
|
1992
1991
|
if (encoder) {
|
|
1993
1992
|
var keyValue = encodeValuesOnly ? prefix : encoder(prefix, defaults$1.encoder, charset, 'key', format);
|
|
1994
|
-
if (generateArrayPrefix === 'comma' && encodeValuesOnly) {
|
|
1995
|
-
var valuesArray = split.call(String(obj), ',');
|
|
1996
|
-
var valuesJoined = '';
|
|
1997
|
-
for (var i = 0; i < valuesArray.length; ++i) {
|
|
1998
|
-
valuesJoined += (i === 0 ? '' : ',') + formatter(encoder(valuesArray[i], defaults$1.encoder, charset, 'value', format));
|
|
1999
|
-
}
|
|
2000
|
-
return [formatter(keyValue) + (commaRoundTrip && isArray$1(obj) && valuesArray.length === 1 ? '[]' : '') + '=' + valuesJoined];
|
|
2001
|
-
}
|
|
2002
1993
|
return [formatter(keyValue) + '=' + formatter(encoder(obj, defaults$1.encoder, charset, 'value', format))];
|
|
2003
1994
|
}
|
|
2004
1995
|
return [formatter(prefix) + '=' + formatter(String(obj))];
|
|
@@ -2013,6 +2004,9 @@ var stringify$1 = function stringify(
|
|
|
2013
2004
|
var objKeys;
|
|
2014
2005
|
if (generateArrayPrefix === 'comma' && isArray$1(obj)) {
|
|
2015
2006
|
// we need to join elements in
|
|
2007
|
+
if (encodeValuesOnly && encoder) {
|
|
2008
|
+
obj = utils$1.maybeMap(obj, encoder);
|
|
2009
|
+
}
|
|
2016
2010
|
objKeys = [{ value: obj.length > 0 ? obj.join(',') || null : void undefined }];
|
|
2017
2011
|
} else if (isArray$1(filter)) {
|
|
2018
2012
|
objKeys = filter;
|
|
@@ -2045,7 +2039,7 @@ var stringify$1 = function stringify(
|
|
|
2045
2039
|
commaRoundTrip,
|
|
2046
2040
|
strictNullHandling,
|
|
2047
2041
|
skipNulls,
|
|
2048
|
-
encoder,
|
|
2042
|
+
generateArrayPrefix === 'comma' && encodeValuesOnly && isArray$1(obj) ? null : encoder,
|
|
2049
2043
|
filter,
|
|
2050
2044
|
sort,
|
|
2051
2045
|
allowDots,
|
|
@@ -2244,7 +2238,8 @@ var isoSentinel = 'utf8=%26%2310003%3B'; // encodeURIComponent('✓')
|
|
|
2244
2238
|
var charsetSentinel = 'utf8=%E2%9C%93'; // encodeURIComponent('✓')
|
|
2245
2239
|
|
|
2246
2240
|
var parseValues = function parseQueryStringValues(str, options) {
|
|
2247
|
-
var obj = {};
|
|
2241
|
+
var obj = { __proto__: null };
|
|
2242
|
+
|
|
2248
2243
|
var cleanStr = options.ignoreQueryPrefix ? str.replace(/^\?/, '') : str;
|
|
2249
2244
|
var limit = options.parameterLimit === Infinity ? undefined : options.parameterLimit;
|
|
2250
2245
|
var parts = cleanStr.split(options.delimiter, limit);
|
|
@@ -2595,14 +2590,14 @@ var BlankCard = function BlankCard(_ref) {
|
|
|
2595
2590
|
title = _ref.title,
|
|
2596
2591
|
description = _ref.description,
|
|
2597
2592
|
_ref$onClick = _ref.onClick,
|
|
2598
|
-
onClick = _ref$onClick === void 0 ?
|
|
2593
|
+
onClick = _ref$onClick === void 0 ? neetocist.noop : _ref$onClick,
|
|
2599
2594
|
_ref$disabled = _ref.disabled,
|
|
2600
2595
|
disabled = _ref$disabled === void 0 ? false : _ref$disabled;
|
|
2601
2596
|
return /*#__PURE__*/React__default["default"].createElement("div", {
|
|
2602
2597
|
className: "neeto-ui-rounded-lg neeto-ui-bg-white hover:neeto-ui-bg-white neeto-ui-border-primary-500 outline-none flex cursor-pointer flex-col items-center justify-center border border-dashed p-6 transition-all duration-300 ease-in-out hover:border-solid focus:border-solid",
|
|
2603
2598
|
"data-cy": "start-from-scratch-button",
|
|
2604
2599
|
tabIndex: 0,
|
|
2605
|
-
onClick: !disabled ? onClick :
|
|
2600
|
+
onClick: !disabled ? onClick : neetocist.noop
|
|
2606
2601
|
}, /*#__PURE__*/React__default["default"].createElement("div", {
|
|
2607
2602
|
className: "neeto-ui-text-primary-500 mb-4"
|
|
2608
2603
|
}, /*#__PURE__*/React__default["default"].createElement(Icon, {
|
|
@@ -2756,7 +2751,8 @@ var List = function List(_ref) {
|
|
|
2756
2751
|
hasNextPage = _useFetchTemplates$ha === void 0 ? false : _useFetchTemplates$ha,
|
|
2757
2752
|
fetchNextPage = _useFetchTemplates.fetchNextPage,
|
|
2758
2753
|
isTemplatesLoading = _useFetchTemplates.isLoading,
|
|
2759
|
-
|
|
2754
|
+
_useFetchTemplates$da = _useFetchTemplates.data,
|
|
2755
|
+
data = _useFetchTemplates$da === void 0 ? {} : _useFetchTemplates$da;
|
|
2760
2756
|
var _useInfiniteScroll = useInfiniteScroll({
|
|
2761
2757
|
loading: isTemplatesLoading,
|
|
2762
2758
|
hasNextPage: hasNextPage,
|
|
@@ -2774,9 +2770,12 @@ var List = function List(_ref) {
|
|
|
2774
2770
|
if (isTemplatesLoading) {
|
|
2775
2771
|
return /*#__PURE__*/React__default["default"].createElement(PageLoader__default["default"], null);
|
|
2776
2772
|
}
|
|
2777
|
-
var tags = data.tags,
|
|
2778
|
-
|
|
2779
|
-
|
|
2773
|
+
var _data$tags = data.tags,
|
|
2774
|
+
tags = _data$tags === void 0 ? [] : _data$tags,
|
|
2775
|
+
_data$templates = data.templates,
|
|
2776
|
+
templates = _data$templates === void 0 ? [] : _data$templates,
|
|
2777
|
+
_data$templatesCount = data.templatesCount,
|
|
2778
|
+
templatesCount = _data$templatesCount === void 0 ? 0 : _data$templatesCount;
|
|
2780
2779
|
var categories = [_objectSpread$2(_objectSpread$2({}, DEFAULT_CATEGORY), {}, {
|
|
2781
2780
|
count: templatesCount
|
|
2782
2781
|
})].concat(_toConsumableArray(tags));
|
|
@@ -2839,7 +2838,7 @@ var List = function List(_ref) {
|
|
|
2839
2838
|
icon: isCreating ? neetoui.Spinner : SvgCustom,
|
|
2840
2839
|
title: t("neetoTemplate.templates.blankCard.title"),
|
|
2841
2840
|
onClick: onCreate
|
|
2842
|
-
}), templates
|
|
2841
|
+
}), templates.map(function (template, index) {
|
|
2843
2842
|
return /*#__PURE__*/React__default["default"].createElement(Card, {
|
|
2844
2843
|
key: index,
|
|
2845
2844
|
template: template,
|
|
@@ -2917,9 +2916,9 @@ var CreateTemplateModal = function CreateTemplateModal(_ref) {
|
|
|
2917
2916
|
isCreating = _ref.isCreating,
|
|
2918
2917
|
refetchResource = _ref.refetchResource,
|
|
2919
2918
|
_ref$onCreate = _ref.onCreate,
|
|
2920
|
-
onCreate = _ref$onCreate === void 0 ?
|
|
2919
|
+
onCreate = _ref$onCreate === void 0 ? neetocist.noop : _ref$onCreate,
|
|
2921
2920
|
_ref$afterCreate = _ref.afterCreate,
|
|
2922
|
-
afterCreate = _ref$afterCreate === void 0 ?
|
|
2921
|
+
afterCreate = _ref$afterCreate === void 0 ? neetocist.noop : _ref$afterCreate;
|
|
2923
2922
|
var _useState = React.useState(TEMPLATE_SCREENS.LIST),
|
|
2924
2923
|
_useState2 = _slicedToArray(_useState, 2),
|
|
2925
2924
|
currentScreen = _useState2[0],
|
|
@@ -3054,7 +3053,7 @@ var Tags = function Tags(_ref) {
|
|
|
3054
3053
|
return onUpdate([].concat(_toConsumableArray(selectedTags), [newTag]));
|
|
3055
3054
|
};
|
|
3056
3055
|
var handleTagRemove = function handleTagRemove(removedTag) {
|
|
3057
|
-
var updatedTags =
|
|
3056
|
+
var updatedTags = neetocist.removeBy({
|
|
3058
3057
|
value: removedTag.value
|
|
3059
3058
|
}, selectedTags);
|
|
3060
3059
|
onUpdate(updatedTags);
|
|
@@ -3121,7 +3120,7 @@ var buildSelectOptionsBy = function buildSelectOptionsBy(labelField, options) {
|
|
|
3121
3120
|
};
|
|
3122
3121
|
var buildTagOptions = function buildTagOptions() {
|
|
3123
3122
|
var tags = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
|
|
3124
|
-
return
|
|
3123
|
+
return neetocist.renameKeys({
|
|
3125
3124
|
id: "value",
|
|
3126
3125
|
name: "label"
|
|
3127
3126
|
}, tags);
|