vue-rule-script.html 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303
  1. <div id="app">
  2. <div class="app-wrapper" :class="{'is-preview':preview}">
  3. <div class="editor"
  4. v-if="!preview && !legacy"
  5. v-cloak
  6. v-on:change="this.handleStateUpdate()"
  7. >
  8. <div class="controls">
  9. <vue-button class="primary is-large" @click="clickPreview" :icon="icons.view">Preview</vue-button>
  10. </div>
  11. <div class="details">
  12. <div class="label-group">
  13. <label class="label" for="">
  14. <span>What is the community's name?</span>
  15. <input type="text" v-model="computedState.rule.name" @change="state.rule.ruleID = slugify(computedState.rule.name)">
  16. </label>
  17. <label class="label">
  18. <span>Icon:</span>
  19. <div class="dropdown">
  20. <label v-for="(icon, iconName, idx) in ruleIcons" :key="idx"
  21. :class="{ selected: computedState.rule.icon == icon }">
  22. <input type="radio" id="" :selected="computedState.rule.icon == icon" :value="icon" v-model="computedState.rule.icon">
  23. <div><img :src="icon" :alt="iconName"></div>
  24. </label>
  25. <label class="default">
  26. <div><img :src="icons.blank"></div>
  27. </label>
  28. </div>
  29. </label>
  30. </div>
  31. <label class="label" for="">
  32. <span>Summarize its structure:</span>
  33. <textarea v-model="computedState.rule.summary"></textarea>
  34. </label>
  35. </div>
  36. <div class="rule__modules" :class="{ target: holding }">
  37. <label class="label" for="" v-if="computedState.rule.name"><icon :icon="computedState.rule.icon"></icon>[[computedState.rule.name]]</label>
  38. <div
  39. class="modules__dropzone modules__grid"
  40. :data-module-id="computedState.rule.ruleID"
  41. .module="computedState.rule"
  42. @drop.prevent="dropOnRule" @dragenter.prevent @dragover.prevent
  43. >
  44. <div v-if="computedState.rule.modules.length < 1">Drag rules from the library below here, or create your own.</div>
  45. <module
  46. v-for="module in computedState.rule.modules"
  47. :key="module"
  48. @click="handleClickEditModule"
  49. :module="module"
  50. draggable="true"
  51. @dragstart="rearrangeModule"
  52. ></module>
  53. </div>
  54. </div>
  55. <div class="module-editor__wrapper">
  56. <div class="module-editor">
  57. <module
  58. class="module-editor__label"
  59. hide-submodules
  60. :module="computedState.editor.module"
  61. draggable="false"
  62. v-if="computedState.editor.module.name"
  63. ></module>
  64. <div class="module-editor__right">
  65. <vue-button class="success" :icon="icons.plus" @click="clickAddModule" v-if="!moduleContains(computedState.editor.module) && computedState.editor.module && computedState.editor.module.name">Add</vue-button>
  66. <vue-button class="danger" :icon="icons.minus" @click="clickRemoveModule" v-if="moduleContains(computedState.editor.module)">Remove</vue-button>
  67. </div>
  68. <div class="module-editor__fields">
  69. <div class="label-group">
  70. <label class="label">
  71. <span>Module name:</span>
  72. <input class="input-stack" type="text" v-model="computedState.editor.module.name" @change="computedState.editor.module.moduleID = slugify(computedState.editor.module.name)">
  73. </label>
  74. <label class="label">
  75. <span>Icon:</span>
  76. <div class="dropdown">
  77. <label v-for="(icon, iconName, idx) in moduleIcons" :key="idx" :class="{ selected: computedState.editor.module.icon == icon }">
  78. <input type="radio" id="" :selected="computedState.editor.module.icon == icon" :value="icon" v-model="computedState.editor.module.icon">
  79. <div><img :src="icon" :alt="iconName"></div>
  80. </label>
  81. <label class="default"><div><img :src="icons.blank"></div></label>
  82. </div>
  83. </label>
  84. </div>
  85. <label class="label">
  86. <span>Module Summary:</span>
  87. <textarea v-model="computedState.editor.module.summary"></textarea>
  88. </label>
  89. <label class="label configs">
  90. <table>
  91. <tr v-for="(value, key) in computedState.editor.module.config">
  92. <td>[[key]]</td>
  93. <td><input type="text"
  94. v-model="computedState.editor.module.config[key]" /></td>
  95. <td style="vertical-align: initial">
  96. <span class="config-button"
  97. @click="removeConfig([[key]])">
  98. <img :src="icons.minus" alt="Remove">
  99. </span>
  100. </td>
  101. </tr>
  102. <tr >
  103. <td><input id="newConfigKey"
  104. type="text"
  105. value="Configuration" /></td>
  106. <td>
  107. <input id="newConfigValue"
  108. type="text"
  109. value="Value" /></td>
  110. <td style="vertical-align: initial">
  111. <span class="config-button"
  112. @click="addConfig">
  113. <img :src="icons.plus" alt="Add">
  114. </span>
  115. </td>
  116. </tr>
  117. </table>
  118. </label>
  119. <!-- Working on custom module library
  120. <div class="label-group">
  121. <label class="label">
  122. <span>Module ID:</span>
  123. <input type="text" v-model="computedState.editor.module.moduleID">
  124. </label>
  125. <label class="label">
  126. <span>Type:</span>
  127. <input type="text" v-model="computedState.editor.module.type">
  128. </label>
  129. </div>
  130. <div class="modules__grid" v-if="computedState.editor.module.modules">
  131. <module
  132. v-for="(module, idx) in computedState.editor.module.modules"
  133. :key="idx"
  134. @click="handleClickEditModule"
  135. :module="module"
  136. ></module>
  137. </div>
  138. <label for="">
  139. <vue-button @click="saveEditor">Save</vue-button>
  140. </label>
  141. <label for="" v-if="customModules.includes(computedState.editor.module)">
  142. <vue-button @click="deleteModule(computedState.editor.module)">Delete</vue-button>
  143. </label> -->
  144. </div>
  145. </div>
  146. <div class="label-group is-mobile">
  147. <div class="module" @click="newCustomModule">
  148. <span class="plus"><img :src="icons.plus" alt="Add"></span>
  149. Create Custom Module
  150. </div>
  151. <div class="module-editor__empty">
  152. <small>Or click a module to start editing it.</small>
  153. </div>
  154. </div>
  155. </div>
  156. <div class="modules">
  157. <div class="tabs">
  158. <div class="tab__control" v-for="(type, name) in moduleTypes" :key="name" @click="moduleLibrary = name" :class="{ active: moduleLibrary == name}">
  159. <img :src="type.icon" :alt="name"><span class="tab__control-name">[[ name ]]</span>
  160. </div>
  161. </div>
  162. <div class="tab__pane">
  163. <div class="modules__type" v-for="(type, name) in moduleTypes" :key="name" v-show="moduleLibrary == name" :test="name">
  164. <p>[[ type.question ]]</p>
  165. <div class="modules__grid">
  166. <module
  167. v-for="(module, index) in getModulesByType(name)"
  168. :key="index"
  169. :module="module"
  170. @click="handleClickCopyModule"
  171. has-grain
  172. draggable="true"
  173. @dragstart="startDragModule"
  174. ></module>
  175. </div>
  176. </div>
  177. </div>
  178. </div>
  179. <div class="creator">
  180. <label class="label" for="">
  181. <span><img src="/assets/tabler_icons/pencil.svg"> Created By</span>
  182. <input type="text" v-model="computedState.rule.creator.name" placeholder="your name">
  183. </label>
  184. <label class="label" for="">
  185. <span><img src="/assets/tabler_icons/globe.svg"> Creator URL</span>
  186. <input type="text" v-model="computedState.rule.creator.url" placeholder="https://yourwebsite.org">
  187. </label>
  188. </div>
  189. </div>
  190. <div class="rule" v-show="preview" v-if="!legacy">
  191. <div class="controls">
  192. <vue-button class="primary is-large" @click="clickPreview" :icon="icons.edit" v-if="!view">Edit</vue-button>
  193. </div>
  194. <h1><icon :icon="computedState.rule.icon" v-if="computedState.rule.icon"></icon> [[computedState.rule.name]]</h1>
  195. <p>[[computedState.rule.summary]]</p>
  196. <div class="modules__grid" :data-module-id="computedState.rule.ruleID" .module="computedState.rule">
  197. <module-display
  198. v-for="module in computedState.rule.modules"
  199. :key="module"
  200. :module="module"
  201. ></module-display>
  202. </div>
  203. <ul class="module-list">
  204. <module-list v-for="(module, index) in computedState.rule.modules" :key="index" :module="module" v-if="computedState.rule.modules"></module-list>
  205. </ul>
  206. <div class="rule__creator" v-if="computedState.rule.creator.name">
  207. Created By
  208. <img src="/assets/tabler_icons/pencil.svg">
  209. <span v-if="computedState.rule.creator.url"><a :href="computedState.rule.creator.url">[[computedState.rule.creator.name]]</a></span>
  210. <span v-else>[[computedState.rule.creator.name]]</span>
  211. </div>
  212. </div>
  213. <div class="rule legacy" v-if="legacy && preview">
  214. <h1>[[computedState.rule.name]]</h1>
  215. <p>[[computedState.rule.summary]]</p>
  216. <div id="rule-builder" class="rulebuilder">
  217. <div id="module-input" class="rulebuilder_input modules__grid" v-html="computedState.rule.modules">
  218. </div>
  219. <div id="builder-field" class="rulebuilder_list">
  220. </div>
  221. </div>
  222. <div v-html="computedState.rule.rulewriter"></div>
  223. <div class="lineage" v-if="computedState.rule.lineage" v-html="computedState.rule.lineage"></div>
  224. <div class="rule__creator" v-if="computedState.rule.creatorName">
  225. Created By
  226. <img src="/assets/tabler_icons/pencil.svg">
  227. <span v-if="computedState.rule.creatorUrl"><a :href="computedState.rule.creatorUrl">[[computedState.rule.creatorName]]</a></span>
  228. <span v-else>[[computedState.rule.creatorName]]</span>
  229. </div>
  230. </div>
  231. <div class="btn-group" v-if="!legacy && !view">
  232. <vue-button class="primary is-large" @click="handleClickPublish" :icon="icons.publish" :loading="publishing">Publish</vue-button>
  233. <vue-button class="is-large" @click="handleClickDownload" :icon="icons.download">Download</vue-button>
  234. <vue-button class="is-large" @click="handleClickImport" :icon="icons.upload">Import <div class="btn-cover">coming soon!</div></vue-button>
  235. </div>
  236. <div class="btn-group" v-if="view && !legacy">
  237. <vue-button class="primary is-large" @click="clickPreview" :icon="icons.fork">Fork &amp; Edit</vue-button>
  238. <vue-button class="is-large" @click="handleClickDownload" :icon="icons.download">Download</vue-button>
  239. </div>
  240. </div>
  241. <div id="rule-export" v-show="false" v-if="!legacy">
  242. <h1>[[computedState.rule.name]]</h1>
  243. <p>[[computedState.rule.summary]]</p>
  244. <ul class="module-list">
  245. <module-list v-for="(module, index) in computedState.rule.modules" :key="index" :module="module" v-if="computedState.rule.modules" hide-icon></module-list>
  246. </ul>
  247. <hr>
  248. <h2>Created By</h2>
  249. <p v-if="computedState.rule.creator.url"><a :href="computedState.rule.creator.url">[[computedState.rule.creator.name]]</a></p>
  250. <p v-else>[[computedState.rule.creator.name]]</p>
  251. </div>
  252. </div>
  253. <script src="/assets/js/vue.global.js"></script>
  254. <script src="/assets/DragDropTouch.js"></script>
  255. <script src="https://unpkg.com/stein-js-client"></script>
  256. <script src="https://cdnjs.cloudflare.com/ajax/libs/js-yaml/4.1.0/js-yaml.min.js" defer
  257. integrity="sha512-CSBhVREyzHAjAFfBlIBakjoRUKp5h7VSweP0InR/pAJyptH7peuhCsqAI/snV+TwZmXZqoUklpXp6R6wMnYf5Q=="
  258. crossorigin="anonymous" referrerpolicy="no-referrer"></script>
  259. <script src="https://unpkg.com/turndown/dist/turndown.js" defer></script>
  260. <script>
  261. let global = {};
  262. global.modules = [
  263. {% assign modules_array = site.modules | sort: "type" %}
  264. {% for module in modules_array %}
  265. {
  266. name: "{{ module.title | escape }}",
  267. url: "{{ site.baseurl }}{{ module.permalink }}",
  268. moduleID: "{{ module.slug }}",
  269. icon: "{{ site.data.module_types[module.type].icon | default: 'null'}}",
  270. summary: "{{ module.summary }}",
  271. type: "{{ module.type }}",
  272. content: `{{ module.content | markdownify }}`,
  273. {% if module.config %}
  274. config: {
  275. {% for config in module.config %}
  276. "{{ config[0] }}": "{{ config[1] }}"
  277. {% unless forloop.last %}, {% endunless %}
  278. {% endfor %}
  279. },
  280. {% endif %}
  281. readonly: true,
  282. modules: []
  283. } {% unless forloop.last %}, {% endunless %}
  284. {% endfor %}
  285. ];
  286. // global.url = "{{ site.url }}{{ site.baseurl }}";
  287. global.url = "https://communityrule.info";
  288. global.rule = {{ page.rule | jsonify }};
  289. </script>
  290. <script src="/assets/js/vue.rules.js"></script>